1. 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 support
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);
2. Set by Wallpapermanager
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"/>
Android Settings Wallpaper