It seems that sharing data to other apps on Android M is only possible when the other app has manually asked for READ_EXTERNAL_STORAGE permission, and I am wondering if anyone knows a way around this without manually opening all apps I can share to and selecting Storage permission.
For example I have the following Intent to share some data:
Intent shareIntent = new Intent(Intent.ACTION_SEND);
shareIntent.setType("image/*");
shareIntent.putExtra(Intent.EXTRA_SUBJECT, "Some Image Subject");
shareIntent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(someFile));
startActivity(Intent.createChooser(shareIntent, "Share via..."));
Assume someFile
exists and that i have already followed the recommended Runtime Permission model suggested at http://developer.android.com/training/permissions/requesting.html and the user has agreed to allowing my Permission, so the File was in fact created on the system.
Is there a way to tell the Application I am sharing to, that I have granted this permission to my user can you please grant this on my behalf?
This does not work :
shareIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
According to the documentation:
int FLAG_GRANT_READ_URI_PERMISSION
If set, the recipient of this Intent will be granted permission to perform read operations on the URI in the Intent's data and any URIs specified in its ClipData.
And even more interesting that if this flag is set and i share to Gmail, the flag is not detected and Google does not prompt to request the permission but rather just catches the Exception and does not attach my file.
Any help would be appreciated.