I am creating a wallpaper app for the android platform, and I have my XML set up perfectly, but I cannot figure out a good procedure to set the selected photo to the home screen/lock screen via button. Any input is appreciated greatly.
Asked
Active
Viewed 1,000 times
0
-
Please check this link, it's will help you: http://stackoverflow.com/questions/20053919/programmatically-set-android-phones-background – Hong Thai Sep 21 '15 at 06:41
-
here is a tutorial using the WallpaperManager -- http://android-er.blogspot.in/2011/03/set-wallpaper-using-wallpapermanager.html – Tasos Sep 21 '15 at 06:49
1 Answers
0
Try this:
add this code in your Manifest.xml
<uses-permission android:name="android.permission.SET_WALLPAPER"/>
and then you can set the background with this code:
Button buttonSetWallpaper = (Button)findViewById(R.id.set);
ImageView imagePreview = (ImageView)findViewById(R.id.preview);
imagePreview.setImageResource(R.drawable.five);
buttonSetWallpaper.setOnClickListener(new Button.OnClickListener(){
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
WallpaperManager myWallpaperManager
= WallpaperManager.getInstance(getApplicationContext());
try {
myWallpaperManager.setResource(R.drawable.five);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}});
it will work.

Rahmat Aryanto
- 28
- 9