国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 系統 > Android > 正文

調用android動態壁紙的實例介紹

2020-02-21 17:34:53
字體:
來源:轉載
供稿:網友

實際上動態墻紙的實現是在活動中調用動態墻紙服務,通過綁定服務獲取IwallPaper服務,并在接口中調用attach函數來實現墻紙調用,那么調用android動態壁紙的實例介紹大家都了解嗎?今天就讓武林技術頻道小編帶你一起來了解一下吧!

代碼中有用到兩個接口

IWallpaperService mService;

IWallpaperEngine mEngine;

我們可以看到該目錄下面有三個aidl接口,分別是

復制代碼 代碼如下:

interface IWallpaperConnection {

void attachEngine(IWallpaperEngine engine);

ParcelFileDescriptor setWallpaper(String name);

}

oneway interface IWallpaperService {

void attach(IWallpaperConnection connection,

IBinder windowToken, int windowType, boolean isPreview,

int reqWidth, int reqHeight);

}


oneway interface IWallpaperEngine {

void setDesiredSize(int width, int height);

void setVisibility(boolean visible);

void dispatchPointer(in MotionEvent event);

void dispatchWallpaperCommand(String action, int x, int y, int z, in Bundle extras);

void destroy();

}

定義壁紙管理和壁紙信息變量

復制代碼 代碼如下:

private WallpaperManager mWallpaperManager = null;

private WallpaperInfo mWallpaperInfo = null;

private WallpaperConnection mWallpaperConnection = null;

private Intent mWallpaperIntent;

初始化這些變量

復制代碼 代碼如下:

mWallpaperManager = WallpaperManager.getInstance(this);

mWallpaperInfo = mWallpaperManager.getWallpaperInfo();//如果返回null則說明當前不是動態壁紙

mWallpaperIntent = new Intent(WallpaperService.SERVICE_INTERFACE);

mWallpaperIntent.setClassName(mWallpaperInfo.getPackageName(), mWallpaperInfo.getServiceName());

綁定動態壁紙服務

復制代碼 代碼如下:

bindService(mIntent, this, Context.BIND_AUTO_CREATE);

IWallpaperService mService;//這里有一個adil接口

在連接監聽中試著attach

復制代碼 代碼如下:

public void onServiceConnected(ComponentName name, IBinder service) {

mService = IWallpaperService.Stub.asInterface(service);

try {

mService.attach(this, view.getWindowToken(),

// WindowManager.LayoutParams.TYPE_APPLICATION_MEDIA_OVERLAY,
WindowManager.LayoutParams.TYPE_APPLICATION_MEDIA,

true, root.getWidth(), root.getHeight());

} catch (RemoteException e) {

Log.w("", "Failed attaching wallpaper; clearing", e);
}
}


以上是調用android動態壁紙的實例介紹,更多內容盡在武林技術頻道網!

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 黑龙江省| 陇南市| 陵川县| 大荔县| 九龙城区| 特克斯县| 通化县| 双辽市| 石家庄市| 彭山县| 开平市| 云南省| 逊克县| 伊春市| 土默特右旗| 寿光市| 新邵县| 连城县| 牙克石市| 霍邱县| 定日县| 南陵县| 陕西省| 曲阳县| 合山市| 镇宁| 绥化市| 成都市| 塔城市| 松原市| 新巴尔虎左旗| 南靖县| 常德市| 张家界市| 札达县| 确山县| 阿合奇县| 龙里县| 拉孜县| 固原市| 大理市|