Thursday, February 21, 2019

Set image as wallaper

We want to use an image to set as phone wallaper.
Add user permission in AndroidManifest.
<uses-permission android:name="android.permission.SET_WALLPAPER" />


Add these lines in code.
WallpaperManager myWallpaperManager = WallpaperManager.getInstance(getApplicationContext());          
try {                     myWallpaperManager.setResource(R.drawable.abc);

Toast.makeText(getBaseContext(), "Success set as wallpaper", Toast.LENGTH_SHORT).show();

} catch (IOException e) {
Toast.makeText(getBaseContext(), "Error set as wallpaper", Toast.LENGTH_SHORT).show();
}


         

No comments:

Post a Comment