Simple instance of Android dynamic wallpaper call _android

Source: Internet
Author: User

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.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.