0

I have a GridView where I'm loading a bunch of images with Picasso library with urls.

enter image description here

What i'm looking for is a way to allow to the user pick up the image and then set the image picked as a background on the user's phone.

The only thing that i need to know is how take that url (i have that url picked as string already) and set it as background in the user's phone.

I'm working with Android Studio.

MahlerFive
  • 5,159
  • 5
  • 30
  • 40
Fernando Torres
  • 460
  • 7
  • 24

2 Answers2

2

First you'll need to download that image and get its bitmap, see this answer

Then you can call WallpaperManager to set the background, see this answer

Alex Timonin
  • 1,872
  • 18
  • 31
  • Thanks. Now I have setted the background from that url into the user's phone, i send you a screenshot. Happy crhistmas. https://imgur.com/a/dXKZ35h – Fernando Torres Dec 26 '18 at 05:35
1

Use an image loading library like Picasso. With Picasso all you need to put into your click listener is:

Handler uiHandler = new Handler(Looper.getMainLooper());
    uiHandler.post(new Runnable(){
        @Override
        public void run() {
            Bitmap result=Picasso.with(context)
                  .load(imageURL)
                  .get();

         WallpaperManager wallpaperManager = WallpaperManager.getInstance(context);
                try {
                    wallpaperManager.setBitmap(result);
                } catch (IOException ex) {
                    ex.printStackTrace();
                }
        }
    });