Android Set desktop background image to fit the screen size

Source: Internet
Author: User

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

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.