0

I am developing an app inside which I have an image gallery. When I select an image, it opens in another fragment in an imageView (android:id="@+id/gallery_image") and show in full screen mode.

Everything works well. But I need the functionality of setting that image as device wallpaper. After opening an image, when user press menu button, option menu will appear with only one menu item named 'use as Wallpaper'. On clicking that item, the default intent of android to set as wallpaper (may be android.intent.action.SET_WALLPAPER) will give user an option to set that image as wallpaper for that device. The cropping or other wallpaper setting functionality will be handled by android.

I don't know how to open the wallpaper setting intent and at the same time pass that image to that intent to set as wallpaper. Please give me some working code example. Or is there any better way to do that?

Kaidul
  • 15,409
  • 15
  • 81
  • 150

1 Answers1

0

UPDATE:

For passing the image to the native wallpaper app:

Intent intent = new Intent(Intent.ACTION_SET_WALLPAPER);
startActivity(Intent.createChooser(intent, "Select Wallpaper"));

You can create an item in contextMenu as Set as wallpaper in your app and when the user taps that item, you use this code.


Call this method for setting the selected image as Wallpaper:

public void setWallpaper() {

        Context context = this.getBaseContext(); 
        Bitmap mBitmap = BitmapFactory.decodeResource(getResources(),mImageIds[pos]);
        context.setWallpaper(mBitmap);
}

And add this permission in Android Manifest file:

  <uses-permission android:name="android.permission.SET_WALLPAPER" />
Umer Farooq
  • 7,356
  • 7
  • 42
  • 67
  • thanks for your answer. Actually I know how to set an image as wallpaper. But I want to pass that image to android wallpaper setter intent (what you see when you press menu button and a 'use as'/'set as' item appear) and then android will do the rest (like giving cropping option and setting wallpaper). – Kaidul Sep 12 '13 at 19:26
  • it is not supposed to work. You just open the `SET_WALLPAPER` action and not passing that image. `SET_WALLPAPER` just open possible action to choose images from gallery to set wallpaper. I just want to pass this image to that situation when an image is selected to be cropped and setted as wallpaper. – Kaidul Sep 12 '13 at 19:43
  • It does that automatically. Try it – Umer Farooq Sep 12 '13 at 19:43
  • not working. it gives me option to select image from gallery. – Kaidul Sep 12 '13 at 19:45
  • No you can't do that. I think you really need to rethink your app design. You want to pass image from your app to android launcher. For doing so, you will need to ask the developer of the launcher for how to send data from your app to launcher's wallpaper selector. So the easy solution is to write code for leting user crop an image yourself. Ofcourse after cropping for setting an image as a background, you can use above mentioned code. – Umer Farooq Sep 12 '13 at 19:53