How to start the “set as” intent (wallpaper, contact picture, etc)

后端 未结 3 1367
醉梦人生
醉梦人生 2020-12-29 15:56

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

相关标签:
3条回答
  • 2020-12-29 16:38

    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 讨论(0)
  • 2020-12-29 16:41

    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.

    0 讨论(0)
  • 2020-12-29 16:57

    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).

    0 讨论(0)
提交回复
热议问题