从内部和外部存储中选择文件

时间:2020-04-27 15:17:37

标签: android android-external-storage filepicker

我正在尝试从内部和外部存储中选择文件。我可以从内部存储中选择,但不能从外部存储中选择。其获取文件路径为null。 参见下面的代码。

Intent intent = new Intent();
            intent.setType("application/*");
            intent.setAction(Intent.ACTION_GET_CONTENT);
            startActivityForResult(Intent.createChooser(intent, "Select Pdf"), 103);

我在这里获取文件路径

if (requestCode == 103 && resultCode == RESULT_OK && data != null && data.getData() != null) {
            filePath = data.getData();
            Cursor returnCursor = getContentResolver().query(filePath, null, null, null, null);
            int nameIndex = returnCursor.getColumnIndex(OpenableColumns.DISPLAY_NAME);
            returnCursor.moveToFirst();
            String path = FilePath.getPath(MyActivity.this, filePath);

        }

0 个答案:

没有答案
相关问题