调用android动态壁纸的实例介绍
实际上动态墙纸的实现是在活动中调用动态墙纸服务,通过绑定服务获取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动态壁纸的实例介绍,更多内容尽在爱站技术频道网!