Imagine I'm openeing a file using the standard Intent.ACTION_OPEN_DOCUMENT like this
Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT);
intent.setType("text/plain");
...
startActivityForResult(intent, READ_REQUEST_CODE);
which performs as expected.
In that files content, a file name is mentioned which I like to open without any user interaction (just exchange the file name of the intend result with the one read from the file). By doing this, I'll get an java.lang.SecurityException: Permission Denial: reading com.android.externalstorage.ExternalStorageProvider uri content://com.android.externalstorage.documents/document/primary%3ADownload%2Finc.txt from pid=..., uid=... requires android.permission.MANAGE_DOCUMENTS, or grantUriPermission()
by calling getContentResolver().openInputStream(manipulatedUri)
which is weird as in the AndroidManifest.xml
it is written as follows:
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.MANAGE_DOCUMENTS" />
What it makes even more weird to me is the following: File A includes file name B. If I open it that way, it does not work. But, openening file B first (making it known to the systems ContentResolver instance?) and afterwards openening file A, the programatic load of file B works as expected even after app restart.
Does anybody knows the reason for such a behavior?
API Level 19 is used