【问题标题】:in Android 11 i'm not able to get file path from document optio [duplicate]在 Android 11 中,我无法从文档选项中获取文件路径 [重复]
【发布时间】:2021-12-22 18:57:57
【问题描述】:

check the image for more understanding and thanks in advance. In this screenshot all options are good but I don't want to display the document option here but also need a document to be picked. if there is not any way to hide the option then need help to get the path of file

if (isMediaDocument(uri)) {
            Log.e("URI", "" + uri);
            final String docId = DocumentsContract.getDocumentId(uri);
            Log.e("docId", "" + docId);
            final String[] split = docId.split(":");
            final String type = split[0];
            Log.e("TYPE", "" + type);
            Uri contentUri = null;
            if ("image".equals(type)) {
                contentUri = MediaStore.Images.Media.EXTERNAL_CONTENT_URI;
            } else if ("video".equals(type)) {
                contentUri = MediaStore.Video.Media.EXTERNAL_CONTENT_URI;
            } else if ("audio".equals(type)) {
                contentUri = MediaStore.Audio.Media.EXTERNAL_CONTENT_URI;
            } /*else if ("document".equals(type)) {
                contentUri = uri;
            }*/
            selection = "_id=?";
            selectionArgs = new String[]{split[1]};
            return getDataColumn(context, contentUri, selection, selectionArgs);
        }
        if (isGoogleDriveUri(uri)) {
            return getDriveFilePath(context, uri);
        }
        if (isWhatsAppFile(uri)) {
            return getFilePathForWhatsApp(context, uri);
        }
        if ("file".equalsIgnoreCase(uri.getScheme())) {
            return uri.getPath();
        }
    }

【问题讨论】:

    标签: android android-11


    【解决方案1】:

    您不能将该选项灰显。

    即使您设法实现 getRealPathForUri() 来提供文件系统路径,您的应用在 Android 11+ 设备上也没有读写权限。

    所以你想要的没有意义。

    直接使用uri。

    现在每个人都这样做。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-03-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多