Change contact photo by passing image uri using Intent

24 Views Asked by At

I'm trying to change a contact photo, and the code below allows me to do this. However, it is displaying the Google Photos, Gallery, and Contact apps:

 Intent intent = new Intent(Intent.ACTION_ATTACH_DATA);
 MimeTypeMap map = MimeTypeMap.getSingleton();
 String savedImagePath = imageFile.getAbsolutePath();
 String ext = savedImagePath.substring(savedImagePath.lastIndexOf('.') + 1);
 String mimeType = map.getMimeTypeFromExtension(ext);
 Uri uri;
 if (Build.VERSION.SDK_INT > 23)
     uri = FileProvider.getUriForFile(context, AppUtils.getAppPackageName() + ".fileprovider", imageFile);
 else
     uri = Uri.fromFile(imageFile);
 intent.setDataAndType(uri, mimeType);
 intent.putExtra("mimeType", mimeType);
 intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
 intent.addFlags(Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
 intent.putExtra(MediaStore.EXTRA_OUTPUT, uri);

How I can make it show only the contact apps.

0

There are 0 best solutions below