显示来自存储访问框架android studio的uri路径

时间:2018-12-06 03:00:12

标签: android

我不会使用存储访问框架在TextView中显示URI,但我得到的只是content://com.android.documents/。非常感谢您的帮助。

TextView filePath = findViewById(R.id.filepath);

    if (requestCode == READ_REQUEST_CODE && resultCode == Activity.RESULT_OK) {
        Uri uri = null;
        if (resultData != null) {
            uri = resultData.getData();
            Cursor cursor = getContentResolver().query(uri, null, null, null, null);
            try {
                if (cursor != null && cursor.moveToFirst()) {
                    String displayName = cursor.getString(cursor.getColumnIndex(OpenableColumns.DISPLAY_NAME));
                    filePath.setText(uri.toString());
                }
            } finally {
                cursor.close();
            }
        }
    }

0 个答案:

没有答案