Pregunta

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?

¿Fue útil?

Solución

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" />
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top