Settings for Android Wallpaper

Source: Internet
Author: User
Tags clear screen

This is a universal look at the era of face, mobile phones are the same. Beautiful app to add a lot of color to the mobile phone, then hurry to your girlfriend dress up.

From setting up static wallpapers, to live wallpapers, to lock screen wallpapers, to themes, it's not that simple.

1. Set Static wallpaper

public class Mainactivity extends Activity {@Overrideprotected void onCreate (Bundle savedinstancestate) {super.oncreate (savedinstancestate); Setcontentview (r.layout.activity_main); Wallpapermanager = Wallpapermanager.getinstance (This ); Registerreceiver (Broadcastreceiver, New Intentfilter (intent.action_wallpaper_changed));} Wallpapermanager wallpapermanager;public void OnClick (View v) {switch (V.getid ()) {case File = New File (environment.getexternalstoragedirectory () + "/pictures/field.png"); try {InputStream is = new FileInputStream (file);//contextwrapper method, readable bitmap, inputstream//need Set_wallpaper permission. Read files need write_external_storage permission SetWallpaper (IS);} catch (FileNotFoundException e) {e.printstacktrace ();} catch (IOException e) {e.printstacktrace ();} Break;case load res, InputStream, bitmaptry {wallpapermanager.setresource (R.drawable.frame) ;} catch (IOException e) {e.printstacktrace ();} Break;case Wallpaper try {wallpapermanager.clear ();} CATCH (IOException e) {e.printstacktrace ();}}} Receive wallpaper change broadcast private broadcastreceiver broadcastreceiver = new Broadcastreceiver () {@Overridepublic void OnReceive ( Context context, Intent Intent) {if (Intent.getaction (). Equals (intent.action_wallpaper_changed)) {Toast.maketext ( Mainactivity.this, "changed wallpaper", Toast.length_short). Show ();}};}
<?xml version= "1.0" encoding= "Utf-8"? ><linearlayout android:layout_width= "Match_parent" Android:layout_ height= "match_parent" android:orientation= "vertical" xmlns:android= "" > <button android:id= "@+id/btn_setwallpaper" android:layout_width= "Match_parent" Android:la         yout_height= "Wrap_content" android:onclick= "OnClick" android:text= "SetWallpaper"/> <button         Android:id= "@+id/btn_setwallpaper2" android:layout_width= "match_parent" android:layout_height= "Wrap_content" android:onclick= "OnClick" android:text= "SetWallpaper2"/> <button android:id= "@+id/btn_clea Rwallpaper "android:layout_width=" match_parent "android:layout_height=" Wrap_content "android:onClick= "OnClick" android:text= "Clearwallpaper"/></linearlayout>
2. Set Live Wallpaper, selecting the current wallpaper from the Live wallpaper gallery will trigger the service instantiation and call Oncreateengine

/** * Wrapper service, used to instantiate and manage engine */public class Mywallpaperservice extends Wallpaperservice {private static final String TA G = MyWallpaperService.class.getSimpleName ();p ublic Mywallpaperservice () {super (); LOG.D (TAG, "Mywallpaperservice");} @Overridepublic Engine Oncreateengine () {LOG.D (TAG, "Oncreateengine"); return new Mywallpaperserviceengine (this);}}
/** * Engine encapsulates a surfaceview * <p>surfaceview dual cache mechanism for displaying wallpaper: A front buffer, a back buffer. Assuming that the current display is front, if the content changes, * back on the original basis to draw the content. Then back and front swap positions. <P> */public class Mywallpaperserviceengine extends Wallpaperservice.engine {private static final String TAG = Mywal LpaperServiceEngine.class.getSimpleName ();//30 frameprivate/sec. static final int FPS = 5;private final Handler Handler = NE W Handler ();p ublic mywallpaperserviceengine (wallpaperservice wp) {wp.super ();p aint = new paint ();p Aint.setargb (255, 255, 255, 255);} @Overridepublic void OnCreate (Surfaceholder surfaceholder) {super.oncreate (surfaceholder);} @Overridepublic void onoffsetschanged (float xoffset, float yoffset,float xoffsetstep, float yoffsetstep, int Xpixeloffset,int ypixeloffset) {super.onoffsetschanged (Xoffset, Yoffset, Xoffsetstep, YOffsetStep, XPixelOffset, Ypixeloffset);} @Overridepublic void Ontouchevent (Motionevent event) {super.ontouchevent (event);} timer timer; @Overridepublic void onsurfacecreated (Surfaceholder holDer) {super.onsurfacecreated (holder); timer = new timer (); Timer.schedule (new TimerTask () {@Overridepublic void run () { Drawframe ();}}, 0, 1000/fps);} public void onsurfacedestroyed (Surfaceholder holder) {timer.cancel ();}; Paint paint;float y = 300f;private void Drawframe () {final Surfaceholder holder = Getsurfaceholder (); Canvas Canvas = Null;try{canvas = Holder.lockcanvas (new Rect (+, +, 1100)), if (canvas!=null) {//clear screen, Resets the pixel group Canvas.drawcolor (;//Draw Canvas.drawcircle (300f, y, 200f, paint) on the canvas; y + = 20f;if (y>900f) {y = 300f;}}} Finally{if (canvas!=null) {holder.unlockcanvasandpost (canvas);}} Handler.removecallbacks (Drawsurface);//handler.postdelayed (Drawsurface, 1000/fps);} Private final Runnable drawsurface = new Runnable () {@Overridepublic void run () {drawframe ();}};}
<manifest xmlns:android= "" package= "Com.qinuli.compiletest" Android: Versioncode= "1" android:versionname= "1.0" > <uses-permission android:name= "Android.permission.SET_WALLPAPER" /> <uses-permission android:name= "Android.permission.WRITE_EXTERNAL_STORAGE"/> <uses-sdk Android        oid:minsdkversion= "8" android:targetsdkversion= "/>" <application android:allowbackup= "true"        android:icon= "@drawable/ic_launcher" android:label= "@string/app_name" android:theme= "@style/apptheme" android:permission= "Android.permission.BIND_WALLPAPER" > <activity android:name= "com.qinuli.compiletest.m Ainactivity "> <intent-filter > <action android:name=" Android.intent.action.MAIN "/&gt                ; <category android:name= "Android.intent.category.LAUNCHER"/> </intent-filter> &LT;/ACTIVITY&G        T &lT;activity android:name= "com.qinuli.compiletest.SettingsActivity" ></activity> <service android:name= " Com.qinuli.compiletest.MyWallpaperService "> <intent-filter > <action android:name=" a                 Ndroid.service.wallpaper.WallpaperService "/> </intent-filter> <meta-data Android:name= "Android.service.wallpaper" android:resource= "@xml/mylivewallpaper"/> </service&    Gt </application></manifest>
<wallpaper    xmlns:android= ""    android:author= "@string/ Author "    android:description=" @string/description "    android:thumbnail=" @drawable/wallpapericon "    android:settingsactivity= "Com.qinuli.compiletest.SettingsActivity"/>
<string name= "Author" > Shixin </string><string name= "description" > Live interactive wallpaper </string>
public class Settingsactivity extends Activity {@Overrideprotected void onCreate (Bundle savedinstancestate) { Super.oncreate (savedinstancestate); Setcontentview (r.layout.activity_settings);}}
<?xml version= "1.0" encoding= "Utf-8"? ><linearlayout    android:layout_width= "Match_parent"    Android : layout_height= "match_parent"    android:orientation= "vertical"    xmlns:android= " /apk/res/android ">    <button         android:layout_width=" match_parent "        android:layout_height=" Wrap_ Content "        android:text=" Feel free to ask! " /></linearlayout>

Settings for Android Wallpaper

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: 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.