Storage Access Framework:查询用户选定的文件夹uri时出现不受支持的Uri错误

时间:2019-08-14 15:24:58

标签: android directory uri storage-access-framework unsupportedoperation

我正在为我的应用程序测试存储访问框架。

在我的应用程序中,用户选择一个文件夹作为应用程序本身对文件系统的访问点。

使用此方法:

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);
}

在onActivityResult方法中,以下代码被调用:

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();

}

我在onActivityResult中编写了这段代码以检查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();

我试图在权限请求之前或之后放置此代码,但在两种情况下,我都会收到此错误:

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

这是故障还是我的代码错误?

0 个答案:

没有答案