0

My application has a gallery of Picasso that takes the image of the URL through strings, and a user when clicks on top of some image it opens on another activity and leaves the image on big screen.

In this activity I wanted to leave a button that applies the image to the wallpaper your smartphone.

Code:

https://github.com/tenorius/Picasso-Tutorial

Patrick
  • 5,526
  • 14
  • 64
  • 101
  • you can use WallpaperManager. Here are some examples [example1](https://stackoverflow.com/a/20054193/5308778) and [example2](https://www.android-examples.com/programmatically-set-imageview-as-android-phone-background/). – yashkal Jan 19 '18 at 20:09
  • relevant question: https://stackoverflow.com/questions/1964193/android-how-to-set-the-wallpaper-image – aldok Jan 20 '18 at 05:17
  • Formatting / grammar. – Patrick Jan 21 '18 at 06:42

2 Answers2

0

To set the phone wallpaper you can use the WallpaperManager class.
Get it by using:

WallpaperManager wallpaperManager = WallpaperManager.getInstance(getApplicationContext())

and use the methods setStream(InputStream bitmapData) or setBitmap(Bitmap bitmap) What ever more comfortable for you.

You can find more on it in the documentation: https://developer.android.com/reference/android/app/WallpaperManager.html#setStream(java.io.InputStream)

https://developer.android.com/reference/android/app/WallpaperManager.html#setBitmap(android.graphics.Bitmap)

note that you will have to add

<uses-permission android:name="android.permission.SET_WALLPAPER"/>

to your manifest permissions

This should look like that:

Target target = new Target() {
    @Override
    public void onBitmapLoaded(Bitmap bitmap, Picasso.LoadedFrom from) {
         WallpaperManager wallpaperManager = WallpaperManager.getInstance(getApplicationContext());
         wallpaperManager.setBitmap(bitmap);
    }

    @Override
    public void onBitmapFailed(Drawable errorDrawable) {

    }

    @Override
    public void onPrepareLoad(Drawable placeHolderDrawable) {

    }
};
Picasso.with(getContext()).load(url).into(target);
regev avraham
  • 1,102
  • 1
  • 9
  • 24
0

To set wallpaper in android use below code: By using WallpaperManager Class

Button buttonSetWallpaper = (Button)findViewById(R.id.set); ImageView imagePreview = (ImageView)findViewById(R.id.preview); imagePreview.setImageResource(R.drawable.five); buttonSetWallpaper.setOnClickListener(new Button.OnClickListener() { @Override public void onClick(View arg0) { // TODO Auto-generated method stub WallpaperManager myWallpaperManager = WallpaperManager.getInstance(getApplicationContext()); try { myWallpaperManager.setResource(R.drawable.five); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } });

Need to set permission in Manifest:

<uses-permission android:name="android.permission.SET_WALLPAPER"/>

I hope this helps.

antzshrek
  • 9,276
  • 5
  • 26
  • 43