Get and set the wallpaper of the mobile phone in Android

Source: Internet
Author: User
Package COM. easyWay. android. ui; import Java. io. ioexception; import android. app. activity; import android. app. wallpapermanager; import android. graphics. color; import android. graphics. porterduff; import android. graphics. drawable. drawable; import android. OS. bundle; import android. view. view; import android. view. view. onclicklistener; import android. widget. button; import android. widget. imageview;/*** get and set the wallpaper of the mobile phone in Android *** // get the wallpaper manager * Final wallpapermanager = wallpapermanager. getinstance (this); * // get the wallpaper image * Final drawable wallpaperdrawable = wallpapermanager. getdrawable (); * method for setting wallpaper * // change wallpaper manager. setbitmap (imageview. getdrawingcache (); * @ author longgangbai **/public class androidwallpaperactivity extends activity {final static private int [] mcolors = {color. blue, color. green, color. red, color. ltgray, color. magenta, color. cyan, color. yellow, color. white};/*** initialization of the activity after it is first created. must at least * call {@ link android. app. activity # setcontentview ()} to * describe what is to be displayed in the screen. * // @ override protected void oncreate (bundle savedinstancestate) {// be sure to call the super class. super. oncreate (savedinstancestate); // see Res/layout/wallpaper_2.xml for this // view layout definition, which is being set here as // the content of our screen. setcontentview (R. layout. wallpaper); // obtain the wallpaper manager final wallpapermanager = wallpapermanager. getinstance (this); // get the wallpaper image final drawable wallpaperdrawable = wallpapermanager. getdrawable (); // Image view final imageview = (imageview) findviewbyid (R. id. imageview); // draw the cached imageview. setdrawingcacheenabled (true); // sets the image imageview. setimagedrawable (wallpaperdrawable); // change the wallpaper color. Button randomize = (button) findviewbyid (R. id. randomize); randomize. setonclicklistener (New onclicklistener () {public void onclick (view) {int mcolor = (INT) math. floor (math. random () * mcolors. length); wallpaperdrawable. setcolorfilter (mcolors [mcolor], porterduff. mode. multiply); imageview. setimagedrawable (wallpaperdrawable); // call this method to re-call ondraw to draw the imageview of the entire interface. invalidate () ;}}); // button setwallpaper = (button) findviewbyid (R. id. setwallpaper); setwallpaper. setonclicklistener (New onclicklistener () {public void onclick (view) {try {// change wallpaper wallpapermanager. setbitmap (imageview. getdrawingcache (); finish ();} catch (ioexception e) {e. printstacktrace ();}}});}}

 

Address: http://topmanopensource.iteye.com/blog/1310542 #
 

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.