The background the application that you use the most sometimes become your favorite. What if you have an option to set your homescreen's background right from your application with just a click?
Well this post will show you to change your android phone's home background from your android app. It means that you can change your phone's home screen wallpaper from your app.
2. Now to set the image of your choice as the background of your home screen we have the WallpaperManager class which can be used as follows:
3. You can use the above code in your app on the onClick() method of a button to change the background of your home screen as follows:
Well this post will show you to change your android phone's home background from your android app. It means that you can change your phone's home screen wallpaper from your app.
1. To change the wallpaper of your home screen from your app, first you need to set a permission in your AndroidManifest.xml file as follows:
<uses-permission android:name="android.permission.SET_WALLPAPER"/>
2. Now to set the image of your choice as the background of your home screen we have the WallpaperManager class which can be used as follows:
WallpaperManager myWallpaperManager = WallpaperManager.getInstance(getApplicationContext());
try {
myWallpaperManager.setResource(R.drawable.five);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
3. You can use the above code in your app on the onClick() method of a button to change the background of your home screen as follows:
Button buttonSetWallpaper = (Button)findViewById(R.id.btn);
ImageView imagePreview = (ImageView)findViewById(R.id.imgVw);
imagePreview.setImageResource(R.drawable.sample_img);
buttonSetWallpaper.setOnClickListener(new Button.OnClickListener(){
@Override
public void onClick(View arg0) {
WallpaperManager myWallpaperManager
= WallpaperManager.getInstance(getApplicationContext());
try {
Bitmap icon = BitmapFactory.decodeResource(getResources(),
R.drawable.sample_img);
myWallpaperManager.setBitmap(icon);
Bitmap icon = BitmapFactory.decodeResource(getResources(),
R.drawable.sample_img);
myWallpaperManager.setBitmap(icon);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}});
That's all.
That's all.
No comments:
Post a Comment