How to extract the file name from URI returned from Intent.ACTION_GET_CONTENT?

后端 未结 17 2086
梦如初夏
梦如初夏 2020-11-28 05:09

I am using 3rd party file manager to pick a file (PDF in my case) from the file system.

This is how I launch the activity:

Intent i         


        
17条回答
  •  天涯浪人
    2020-11-28 05:53

    The most condensed version:

    public String getNameFromURI(Uri uri) {
        Cursor c = getContentResolver().query(uri, null, null, null, null);
        c.moveToFirst();
        return c.getString(c.getColumnIndex(OpenableColumns.DISPLAY_NAME));
    }
    

提交回复
热议问题