Search code examples
androidbackground-imageandroid-gallery

set phone background image from gallery


I want to open image from galley and then set that image as phone background. I am able to open the gallery but getting error while setting that image as phone background.


Solution

  • Retrieve the image from the imageUri and save it as a bitmap object. Make sure you have the Set Wallpaper permission in the Android Manifest.

    Bitmap image =MediaStore.Images.Media.getBitmap(getContentResolver(), imageUri);
    
    WallpaperManager myWallpaperManager = WallpaperManager.getInstance(getApplicationContext());
    myWallpaperManager.setBitmap(bitmap);