1

I am trying to create my own wallpaper app and I can't figure out how to start this intent?

enter image description here

What is this intent? How do I pass image to device default wallpaper app?

Slim C.
  • 1,119
  • 4
  • 25
  • 49
  • duplicate of https://stackoverflow.com/questions/22213878/android-set-wallpaper-using-the-set-wallpaper-intent – Shubham Raitka Nov 06 '18 at 13:06
  • The answer in the question you mentioned does not work for me. It gives me "All apps associated with this action have been turned off, blocked, or are not installed" dialog – Slim C. Nov 06 '18 at 13:42

2 Answers2

0

Try following code snippet:

Intent intent = new Intent(Intent.ACTION_ATTACH_DATA);
intent.addCategory(Intent.CATEGORY_DEFAULT);
intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);//add this if your targetVersion is more than Android 7.0+
intent.setDataAndType(uri, "image/jpeg");
intent.putExtra("mimeType", "image/jpeg");
this.startActivity(Intent.createChooser(intent, "Set as:"));

PS:uri should get from FileProvider in Android 7.0+ if your targetVersion is more than7.0+

aolphn
  • 2,950
  • 2
  • 21
  • 30
  • This gave me the following error: "All apps associated with this action have been turned off, blocked, or are not installed." – Slim C. Nov 06 '18 at 13:40
  • Which Anroid version about your device? – aolphn Nov 07 '18 at 01:19
  • I did something in my Huawei Honor V8,and it works fine.By the way you should add `Intent.FLAG_GRANT_READ_URI_PERMISSION` in your Intent at Android 7.0+.I'll reedit my answer. – aolphn Nov 07 '18 at 01:34
  • Will check and update you tomorrow. But it was tested on api 21 and 26 – Slim C. Nov 07 '18 at 15:16
0

You could try this:

private void startWallpaper(){
    final Intent pickWallpaper = new Intent(Intent.ACTION_SET_WALLPAPER);
    Intent chooser = Intent.createChooser(pickWallpaper,"set wallpaeper");
    startActivity(chooser);
}

ref is here

In your manifest file:

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

If you want to pass own img, could do like below:

WallpaperManager wpm = WallpaperManager.getInstance(context);
InputStream ins = new URL("absolute/path/of/image").openStream();
wpm.setStream(ins);
navylover
  • 12,383
  • 5
  • 28
  • 41