Android opening a file with ACTION_GET_CONTENT results into different Uri's

前端 未结 4 753
不思量自难忘°
不思量自难忘° 2020-11-30 23:21

I am trying to open files by using Intent.ACTION_GET_CONTENT.

Dependent on the Android version/device brand the file browser opens and I get the follo

4条回答
  •  误落风尘
    2020-11-30 23:44

    There is a bug I just faced

    final String docId = DocumentsContract.getDocumentId(uri);
    

    return different URI (e.g: content://com.android.providers.downloads.documents/document/11 and sometime content://com.android.providers.downloads.documents/document/abc%aile.jpg in that case Long.valueOf(id) throws an exception to fix that

    String id = DocumentsContract.getDocumentId(uri);
                    if (id.startsWith("raw:")) {
                        id = id.replaceFirst("raw:", "");
                        return id;
                    }
                    final Uri contentUri = ContentUris.withAppendedId(
                        Uri.parse("content://downloads/public_downloads"), Long.valueOf(id));
    
                    return getDataColumn(contentUri, null, null);
    

    do this return the id, it worked for me

提交回复
热议问题