ContentResolver - how to get file name from Uri

后端 未结 7 531
误落风尘
误落风尘 2020-12-30 03:38

I call startActivityForResult with Intent ACTION_GET_CONTENT. Some app returns me data with this Uri:

content://media/external/images/media/18122

I

相关标签:
7条回答
  • 2020-12-30 04:06

    You can get file name from this code, or any other field by modifying the projection

    String[] projection = {MediaStore.MediaColumns.DATA};
    
    ContentResolver cr = getApplicationContext().getContentResolver();
    Cursor metaCursor = cr.query(uri, projection, null, null, null);
    if (metaCursor != null) {
        try {
            if (metaCursor.moveToFirst()) {
                path = metaCursor.getString(0);
            }
        } finally {
            metaCursor.close();
        }
    }
    return path;
    
    0 讨论(0)
提交回复
热议问题