After the call, the dynamic wallpaper is actually displayed behind the activity, while the activity is transparently displayed so that the following dynamic wallpaper is visible, and nothing can be seen if it is not transparent.
Two interfaces useful in the code
Iwallpaperservice Mservice;
Iwallpaperengine Mengine;
We can see that the directory below has three AIDL interfaces, respectively
Copy Code code as follows:
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 ();
}
Define wallpaper management and wallpaper information variables
Copy Code code as follows:
Private Wallpapermanager Mwallpapermanager = null;
Private Wallpaperinfo mwallpaperinfo = null;
Private wallpaperconnection mwallpaperconnection = null;
Private Intent mwallpaperintent;
Initialize these variables
Copy Code code as follows:
Mwallpapermanager = Wallpapermanager.getinstance (this);
Mwallpaperinfo = Mwallpapermanager.getwallpaperinfo ();//If NULL is not currently a dynamic wallpaper
Mwallpaperintent = new Intent (wallpaperservice.service_interface);
Mwallpaperintent.setclassname (Mwallpaperinfo.getpackagename (), Mwallpaperinfo.getservicename ());
Binding Dynamic Wallpaper Service
Copy Code code as follows:
Bindservice (Mintent, this, context.bind_auto_create);
Iwallpaperservice mservice;//Here's a Adil interface.
Trying to attach in connection monitoring.
Copy Code code as follows:
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);
}
}
When Bindservice found that always failed, later found to be a permission issue, only the APK with system privileges can use Wallpaperservice.service_interface services, so the problem becomes how to obtain system permissions.