Several scenarios for Android settings wallpaper

Source: Internet
Author: User

There are many ways to set up wallpaper on Android, there are two main ideas:

1: Set through Wallpapermanager

2: Through the System program settings

The following sections explain separately:

<1> throughWallpapermanagerSet up

This method can be used to set the image as wallpaper directly for all platforms, but it is not possible to crop/adjust the image.

try {    Wallpapermanager wpm = (Wallpapermanager) getactivity (). Getsystemservice (                context.wallpaper_service);    if (wallpaper! = null) {       wpm.setbitmap (bitmap);       LOG.I ("Xzy", "Wallpaper NOT NULL");}    } catch (IOException e) {    log.e (TAG, "Failed to set Wallpaper:" + e);}

You need to declare permissions in Androidmanifest.xml:

<uses-permission android:name = "Android.permission.SET_WALLPAPER"/>

<2> through System program settings

The advantage of the system application setting is that you can crop the picture, set the best wallpaper effect, and the operating experience is consistent with the platform. and this method is not allowed to declare permissions

There are two possible ways to do this.

1: Call system crop activity to set wallpaper by cropping activity:

            Intent Intent = new Intent ("");            int width = getactivity (). Getwallpaperdesiredminimumwidth ();            int height = getactivity (). Getwallpaperdesiredminimumheight ();            Intent.putextra ("Outputx",         width);            Intent.putextra ("Outputy",         height);            Intent.putextra ("Aspectx",         width);            Intent.putextra ("Aspecty",         height);            Intent.putextra ("scale",           true);            Intent.putextra ("Nofacedetection", true);            Intent.putextra ("SetWallpaper",    true);            Intent.putextra ("Data", ((bitmapdrawable) wallpaper). Getbitmap ());            StartActivity (Intent);
There is a drawback to this approach, is an optional action, not a standard action, so that all Android devices support the API, Many devices will appear activitynotfoundexception.

2. Call the system Intent.action_attach_data, the intent will arouse all the settings wallpaper program and set the contact picture program, the user can choose through chooseactivity:

The intent is a standard intent, so all settings will be supported.

                Intent Intent = new Intent (intent.action_attach_data);                Intent.addflags (intent.flag_grant_read_uri_permission);                Intent.putextra ("MimeType", "image/*");                Uri uri = uri.parse (MediaStore.Images.Media                        . Insertimage (Getactivity (). Getcontentresolver (), (                                ( bitmapdrawable) wallpaper). Getbitmap (), NULL, NULL));                Intent.setdata (URI);                Startactivityforresult (Intent, set_wallpaper);

These methods are recommended only for the last one, for simple reasons: good experience and low adaptation cost.

xzy2046, reprint need to indicate. Blog home:

Several scenarios for Android settings wallpaper

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: 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.