5

I searched over the web during the last few weeks (seriously) but I can't find what I need. I just would like to start an intent corresponding to the set as action. It generally offers either Set as wallpaper or Set as contact picture. And then, if more application are installed on the device, they can be listed as well.

Here is an example of what I want :

enter image description here

I precise that I need to support API level 14 and higher. I found getCropAndSetWallpaperIntent but it works only with content URI which is a problem for me, and is only availbable on API lvl 19 and higher.

kalvn
  • 404
  • 5
  • 14
  • possible duplicate of [android set image as contact icon/wallpaper](http://stackoverflow.com/questions/7284142/android-set-image-as-contact-icon-wallpaper) – cygery Oct 30 '14 at 21:50

3 Answers3

12

I found the answer by my self :

Intent intent = new Intent(Intent.ACTION_ATTACH_DATA);
intent.setDataAndType(imageUri, "image/*");
intent.putExtra("jpg", "image/*");
startActivityForResult(Intent.createChooser(intent,
getString(R.string.set_as)), REQUEST_ID_SET_AS_WALLPAPER);

You just have to ensure that the uri is public and will be reachable by the crop application chosen by the user.

kalvn
  • 404
  • 5
  • 14
  • It is working well for setting the wallpaper with Home Screen option but it is not working well while setting the wallpaper for Lock Screen Option. Why? – Gaurav Arora Sep 19 '15 at 05:59
  • 1
    Lock Screen wallpapers are not part of Android Stock. It's usually added by smartphone manufacturers. Therefore, I think it's up to the manufacturer to add the lockscreen option to this intent. There's maybe a parameter to set to take this into account but nothing I know. – kalvn Sep 29 '15 at 10:28
  • Is there any alternative code that is function same in react native ? – Mayur Kukadiya Mar 16 '20 at 17:20
1

This solution worked for me with Uri:

Intent intent = new Intent(Intent.ACTION_ATTACH_DATA);
intent.setDataAndType(contentUri, "image/*");
intent.putExtra("mimeType", "image/*");
intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
startActivity(Intent.createChooser(
                        intent, "Set as:"));
Rahul P.
  • 31
  • 1
  • 12
1

This worked for me :

Intent intent = new Intent(Intent.ACTION_ATTACH_DATA);
intent.addCategory(Intent.CATEGORY_DEFAULT);
//can't use normal URI, because it requires the Uri from file
intent.setDataAndType(Uri.fromFile(new File(uriOfImage)),"image/*");
intent.putExtra("mimeType","image/*");
startActivity(Intent.createChooser(intent,"Set Image"));

You can check that the URI that you pass, should contain the 'file://' prefix (It doesn't work without that).

Harsh Bhardwaj
  • 65
  • 3
  • 10