Android Development set desktop background map to fit resolution

Source: Internet
Author: User

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"/>

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.