android动态开发,android开发实现动态壁纸
釋放雙眼,帶上耳機,聽聽看~!
代碼中有用到兩個接口
IWallpaperService mService;
IWallpaperEngine mEngine;
我們可以看到該目錄下面有三個aidl接口,分別是
復(fù)制代碼 代碼如下:
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();
}
定義壁紙管理和壁紙信息變量
復(fù)制代碼 代碼如下:
private WallpaperManager mWallpaperManager = null;
private WallpaperInfo mWallpaperInfo = null;
private WallpaperConnection mWallpaperConnection = null;
private Intent mWallpaperIntent;
初始化這些變量
復(fù)制代碼 代碼如下:
mWallpaperManager = WallpaperManager.getInstance(this);
mWallpaperInfo = mWallpaperManager.getWallpaperInfo();//如果返回null則說明當(dāng)前不是動態(tài)壁紙
mWallpaperIntent = new Intent(WallpaperService.SERVICE_INTERFACE);
mWallpaperIntent.setClassName(mWallpaperInfo.getPackageName(), mWallpaperInfo.getServiceName());
綁定動態(tài)壁紙服務(wù)
復(fù)制代碼 代碼如下:
bindService(mIntent, this, Context.BIND_AUTO_CREATE);
IWallpaperService mService;//這里有一個adil接口
在連接監(jiān)聽中試著attach
復(fù)制代碼 代碼如下:
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);
}
}
總結(jié)
以上是生活随笔為你收集整理的android动态开发,android开发实现动态壁纸的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 有两个python怎么停用其中一_pyt
- 下一篇: python秒数变分钟_python时间