I'm developing a feature which takes .pdf, .doc and .docx file by using ACTION_GET_CONTENT Intent.
You probably guessed that i need to get Real file path from the uri returned by Intent. I have searched for atleast 3 days to find out code which gives file or real path by using URI. But in those code, only files selected from either Downloads or Recent or internal or some other is working. But couldn't find code which can work for all options viz, Recent, Downloads, Internal storage, SD Card, Drive and Drop box.
These are the solutions i tried.. https://www.dev2qa.com/how-to-get-real-file-path-from-android-uri/
How to get the Full file path from URI
and even this too,
I want code which works in android versions between Android Lollipop and Android Pie.
This is my Intent
Intent intent1 = new Intent(Intent.ACTION_GET_CONTENT);
intent1.addCategory(Intent.CATEGORY_OPENABLE);
intent1.setType(mimeTypes.length == 1 ? mimeTypes[0] : "*/*");
if (mimeTypes.length > 0) {
intent1.putExtra(Intent.EXTRA_MIME_TYPES, mimeTypes);
}
startActivityForResult(Intent.createChooser(intent1, "ChooseFile"), REQUEST_CODE_PICK_FILE);
And everytime i test these codes,
Caused by: java.lang.IllegalStateException: Couldn't read row 0, col -1 from CursorWindow. Make sure the Cursor is initialized correctly before accessing data from it.
java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=1024, result=-1, data=Intent { dat=content://com.android.externalstorage.documents/document/primary:Download/62-2.pdf flg=0x1 }} to activity {com.xxx.xxx.xxx}: java.lang.IllegalStateException: Couldn't read row 0, col -1 from CursorWindow. Make sure the Cursor is initialized correctly before accessing data from it.