3

I am testing the Storage Access Framework for my app.

In my app the user selects a folder as an access point to the filesystem for the app itself.

This method is used:

static public void openPickerForFolderSelection(Activity activity, int requestCode)
{
    Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT_TREE);
    intent.addFlags(Intent.FLAG_GRANT_PERSISTABLE_URI_PERMISSION);
    intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
    intent.addFlags(Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
    activity.startActivityForResult(intent, requestCode);
}

In the onActivityResult method the following code is called:

static public Uri takePermanentReadWritePermissions(Activity activity, Intent data)
{
int takeFlags = data.getFlags()
        &
        (Intent.FLAG_GRANT_READ_URI_PERMISSION | Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
ContentResolver resolver = activity.getContentResolver();
resolver.takePersistableUriPermission(data.getData(),takeFlags);
return data.getData();

}

I wrote this code in onActivityResult to check the Uri:

Cursor c = null;
            ContentResolver contentResolver;
            contentResolver = activityName.getContentResolver();
            c = contentResolver.query(accessPointUri, new String[] {
                    DocumentsContract.Document.COLUMN_DISPLAY_NAME,
                    DocumentsContract.Document.COLUMN_DOCUMENT_ID}, null, null, null);

            while (c.moveToNext())
            {
                String [] s= c.getColumnNames();
                for (int i=0;i<s.length;i++)
                    Log.d("column ",String.valueOf(i)+" "+s[i]);
            }
            c.close();

I tried to put this code before or after the permission request but in both cases I get this error:

java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=13, result=-1, data=Intent { dat=content://com.android.providers.downloads.documents/tree/raw:/storage/emulated/0/Download/accesspoint1 flg=0xc3 }} to activity {com.example.app/com.example.app.activityName}: java.lang.UnsupportedOperationException: Unsupported Uri content://com.android.providers.downloads.documents/tree/raw%3A%2Fstorage%2Femulated%2F0%2FDownload%2Faccesspoint1

Is this a malfunctioning or my code is wrong?

P5music
  • 3,197
  • 2
  • 32
  • 81

0 Answers0