Today to do demo, set up the desktop automatically update the background every day, but the desktop background is the system has been cropped pictures, the internet Baidu, there is an outdated method, the improvement is indeed useful!
Bitmap Bmp=bitmapfactory.decoderesource (Getresources (), BG[DAILYBG]); try {//Super.setwallpaper (BMP); Wallpapermanager instance = wallpapermanager.getinstance (changebgimage.this);//int desiredminimumwidth = GetWindowMa Nager (). Getdefaultdisplay (). GetHeight (); The method is obsolete//int desiredminimumheight = Getwindowmanager (). Getdefaultdisplay (). GetHeight ();//method is obsolete displaymetrics DM = new Displaymetrics (); Getwindowmanager (). Getdefaultdisplay (). Getmetrics (DM); int desiredminimumwidth = Dm.widthpixels; int desiredminimumheight = Dm.heightpixels; LOG.V ("ss", "+desiredminimumwidth"); LOG.V ("ss", "+desiredminimumheight"); Instance.suggestdesireddimensions (Desiredminimumwidth, desiredminimumheight); Instance.setbitmap (BMP); Toast.maketext (changebgimage.this, "Wallpaper setup succeeded", Toast.length_short). Show (); } catch (IOException e) {e.printstacktrace (); } }
The old method has been commented out in the area of getting the screen size, and a new method is used to get the screen size.
Yes also in the manifest file to add permissions, this is very important, I found a half-day only to find that the Suggestdesireddimensions method needs to add permissions
<uses-permission android:name= "Android.permission.SET_WALLPAPER_HINTS"/>
All right, rookie's done.
Android Set desktop background image to fit the screen size