0

I am working on Picasso and have loaded the Images into an ImageView.What should i write on the button code to set it as android wallpaper?

I have success in setting the wallaper from drawable folder.

public class ViewPagerAdapter extends PagerAdapter {
    private Context context;
    private String[] imageUrls;

    ViewPagerAdapter(Context context, String[] imageUrls) {
        this.context = context;
        this.imageUrls = imageUrls;
    }

    @Override
    public int getCount()
    {
        return imageUrls.length;
    }

    @Override
    public boolean isViewFromObject(@NonNull View view, @NonNull Object object) {
        return view == object;
    }

    @NonNull
    @Override
    public Object instantiateItem(@NonNull ViewGroup container, int position) {
        ImageView imageView = new ImageView(context);
        Picasso.get()
                .load(imageUrls[position])
                .fit()
                .centerCrop()
                .into(imageView);
        container.addView(imageView);

        return imageView;
    }

    @Override
    public void destroyItem(@NonNull ViewGroup container, int position, @NonNull Object object) {
        container.removeView((View) object);
    }
}
Zibran
  • 81
  • 2
  • 14

1 Answers1

1

First you get your bitmap image from Picasso like this :

Bitmap mybitmap ;

Picasso.get().load(imageUrl).into(new Target() {
@Override
public void onBitmapLoaded(Bitmap bitmap, Picasso.LoadedFrom from) {
     mybitmap = bitmap;
}

@Override
public void onBitmapFailed(Drawable errorDrawable) { }

@Override
public void onPrepareLoad(Drawable placeHolderDrawable) {}
});

or you can get bitmap from Imageview like this :

imageView.buildDrawingCache();
Bitmap mybitmap= imageView.getDrawingCache();

and then You can set a wallpaper using the WallpaperManager class . For example:

WallpaperManager wallpaperManager = WallpaperManager.getInstance(getApplicationContext());
wallpaperManager.setBitmap(mybitmap);
ismail alaoui
  • 5,748
  • 2
  • 21
  • 38