How to start the "install as" setting (wallpaper, contact image, etc.)

I have searched over the Internet for the past few weeks (seriously), but I can’t find what I need. I just wanted to start an intention corresponding to acting like . He usually offers either Set as wallpaper or Set as contact image . And then, if more applications are installed on the device, they can also be listed.

Here is an example of what I want:

enter image description here

I know for sure that I need to support API level 14 and above. I found getCropAndSetWallpaperIntent , but it only works with content URIs , which is a problem for me and is only available for API lvl 19 and above.

+5
source share
3 answers

I found the answer myself:

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 need to make sure that uri is publicly available and will be accessible using the crop application selected by the user.

+12
source

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:")); 
0
source

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 verify that the URI you pass in must contain the prefix 'file: //' (it does not work without this).

0
source

Source: https://habr.com/ru/post/1205898/


All Articles