0

I'm using Picasso in my app and I managed to open the image in a fullscreen view when the user taps it. Now I would like a button which overlays the image and that sets the image as wallpaper. All images are loaded from URL and stored in a remote server.

I don't know how to achieve this since I'm a veeeery beginner. Can someone help me?

Thanks.

f3d3
  • 5
  • 7

2 Answers2

0

Use this code in button onclicklistener to set image as wallpaper

        StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
            StrictMode.setThreadPolicy(policy);

            WallpaperManager wpm = WallpaperManager.getInstance(getApplicationContext());
           wpm.suggestDesiredDimensions(width, height);
            InputStream ins = null;
            try {
                ins = new URL(Imageurl).openStream();

                wpm.setStream(ins);
                Toast.makeText(ImageViewerActivity.this, "successfully set", Toast.LENGTH_SHORT).show();
            } catch (IOException e) {
                e.printStackTrace();
            }
-1

use ImageLoader instead:

    DisplayImageOptions options = new DisplayImageOptions.Builder()
                    .bitmapConfig(Bitmap.Config.ALPHA_8)
                    .imageScaleType(ImageScaleType.IN_SAMPLE_INT).build();
    ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(
                    ISolaceContext.getAppContext())
                    .discCacheExtraOptions(20, 20, CompressFormat.JPEG, 100, null)
                    .defaultDisplayImageOptions(Media.options).build();
    ImageLoader.getInstance().init(config);
    ImageLoader loader = ImageLoader.getInstance();

    loader.loadImage(url, new SimpleImageLoadingListener() {

       @Override
       public void onLoadingComplete(String imageUri, View view,
                                Bitmap loadedImage) {
          // Now you have the image in your hands as a Bitmap(called: loadedImage) and Now you can do whatever you want with it
          stream.close();
          stream = null;
       }

    });

    loader.clearDiscCache();
    loader.clearMemoryCache();

Now you can use the previously generated Bitmap as a background.converting bitmap to drawable.

Community
  • 1
  • 1
Muhammed Refaat
  • 8,914
  • 14
  • 83
  • 118