Android Set desktop background image to fit screen size
Today, set the desktop automatically update the background every day, but the desktop background is the system has cropped the picture, and then found this 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 = Getwindowmanager (). Getdefaultdisplay (). GetHeight (); 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 settings succeeded, Toast.length_short). Show ();
}
catch (IOException E)
{
E.printstacktrace ();
}
}
is to get the size of the screen the old method has been commented, in a new way to get the size of the screen.
Yes, it's important to add the permissions in the manifest file, and I found out for a long time that the Suggestdesireddimensions method needed permission.
<uses-permission android:name= "Android.permission.SET_WALLPAPER_HINTS"/>
All right, rookie.
How to set up desktop background images on Android
1. How to set up a desktop background picture
Resources Res=getresources ();
Bitmapdrawable bmpdraw= (bitmapdrawable) res.getdrawable (R.drawable.icon);
Bitmap Bmp=bmpdraw.getbitmap ();
try{
SetWallpaper (BMP);
}catch (IOException e) {
E.printstacktrace ();
}
2. Increase the permissions to set up the desktop in manifest
[XHTML] View plaincopy
<uses-permission android:name= "Android.permission.SET_WALLPAPER"/>