微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

当我在最新的 android 11 上从文件选择器中选择文档时无法 pic 文档

如何解决当我在最新的 android 11 上从文件选择器中选择文档时无法 pic 文档

Not able to pick a document from this specific option. Please have look I use the below code for it. I have created one class that processes and gives me a file path.Everythings works fine if I select from image,audio,video and download but not works as I select media from document

 XXPermissions.with(this)
                    .permission(Permission.MANAGE_EXTERNAL_STORAGE)
                    .permission(Permission.CAMERA)
                    .request(new OnPermissionCallback() {
                        @Override
                        public void onGranted(List<String> permissions,boolean all) {
                            Intent chooseFile = new Intent(Intent.ACTION_OPEN_DOCUMENT);
                            chooseFile.addCategory(Intent.CATEGORY_OPENABLE);
                            chooseFile.setType("*/*");
                            chooseFile.putExtra(Intent.EXTRA_LOCAL_ONLY,true);
                            chooseFile = Intent.createChooser(chooseFile,"Choose a file");
                            startActivityForResult(chooseFile,1001);
                        }
                    });


 @Override
protected void onActivityResult(int requestCode,int resultCode,Intent data) {
    switch (requestCode) {
        case 1001:
            if (resultCode == RESULT_OK) {
                Log.e("FILE","" + data.getData());
                Uri uri = data.getData();
                String uriString = uri.toString();
                File myFile = new File(uriString);
                File file = FileUtils.getFile(activity,uri);
                String displayName = null;

                if (uriString.startsWith("content://")) {
                    Cursor cursor = null;
                    try {
                        cursor = getContentResolver().query(uri,null,null);
                        if (cursor != null && cursor.movetoFirst()) {
                            displayName = cursor.getString(cursor.getColumnIndex(OpenableColumns.disPLAY_NAME));
                        }
                    } finally {
                        cursor.close();
                    }
                } else if (uriString.startsWith("file://")) {
                    displayName = myFile.getName();
                }

                uploadFiletoAWS(file.getPath(),ext);
            }
            break;
    }

    super.onActivityResult(requestCode,resultCode,data);
}

if (isMediaDocument(uri)) {
            final String docId = DocumentsContract.getDocumentId(uri);
            final String[] split = docId.split(":");
            final String type = split[0];
            Log.e("TYPE","" + type);
            Uri contentUri;
            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 {
                contentUri = MediaStore.getDocumentUri(context,uri);
            }
            selection = "_id=?";
            selectionArgs = new String[]{split[1]};
            return getDataColumn(context,contentUri,selection,selectionArgs);
        }

enter image description here

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。