Make a list of game pictures, think of adding the wallpaper function, the difference is some information.
1 Don't forget to add permission settings to the Applicationmanifest.xml.
<uses-permission android:name = "Android.permission.SET_WALLPAPER"/>
2, set the method summary of the wallpaper.
There are three ways to set the wallpaper
First through the Wallpapermanager method of the SetBitmap ()
The second through the Wallpapermanager method of the Setresource ()
Third through the SetWallpaper () method provided in the Contextwrapper class
Because Activity inherits Contextthemewrapper, Contextthemewrapper inherits Contextwrapper.
1) invoke the SetBitmap () method in the Singleton class by instantiating the Wallpapermanager class.
Wallpapermanager Wallpapermanager = Wallpapermanager.getinstance (this);
Resources res = getresources ();
Bitmap Bitmap=bitmapfactory.decoderesource (res, getresources (). Getidentifier ("wallpaper" + imageposition, "drawable "," com.ch "));
Wallpapermanager.setbitmap (bitmap);
Toast.maketext (This, "set success", Toast.length_short). Show ();
2) Second through the Wallpapermanager method of the Setresource ()
wallpapermanager Wallpapermanager = Wallpapermanager.getinstance (this);
try {
Wallpapermanager.setresource (Getresources (). Getidentifier ("wallpaper" + imageposition, "drawable", "com.ch"));
Toast.maketext (This, "set success", Toast.length_short). Show ();
} catch (IOException e) {
E.printstacktrace ();
}
3) third through the SetWallpaper () method provided in the Contextwrapper class
Overriding the SetWallpaper () method in Contextwrapper
public void SetWallpaper (InputStream paraminputstream) throws IOException {
Super.setwallpaper (Paraminputstream);
Toast.maketext (This, "set success", 1). Show ();
}
Set the wallpaper code
Resources localresources = Getbasecontext (). Getresources ();
InputStream localInputStream2 = localresources
. Openrawresource (Getresources (). Getidentifier (
"Wallpaper" + imageposition, "drawable", "com.ch"));
try {
SetWallpaper (LOCALINPUTSTREAM2);
} catch (IOException e) {
E.printstacktrace ();
}
For these three kinds, the feeling or the second chapter is the best use, can transform the network picture to the Bitmap type, then calls the system Wallpapermanager to make the corresponding method call.