Search code examples
androidwallpaper

Android Set Wallpaper with URI


I have a URI from the mediastore pointing to a image. I would like to set the wallpaper with this URI. I tryed using BitmapFactory.decodeFile but the problem is if its big it runs out of memory.

Is there another way i can do this.

thanks


Solution

  • This question is a bit old, but what the hey...

    You can get around this problem with the following code. However, if you make the image very small, and then stretch it to fit something very big, you will loose quality. That being said, if the image is so huge you can't even load it, and you just want it to act as your wallpaper, I think you will be fine with the following.

                // use if resizing the image
                BitmapFactory.Options options = new BitmapFactory.Options();
    
                // set to true to set image bounds
                options.inJustDecodeBounds = true; 
    
                // set to 2, 4, 6, etc to create a progressively smaller image
                options.inSampleSize = 2; 
    
                // set to false to prepare image for decoding
                options.inJustDecodeBounds = false; 
    
                bitmap = BitmapFactory.decodeStream(is, null, options);