Google changed the way storage works in Android 10 and 11, i cant get the file path of a file (PDF) while using ACTION_GET_CONTENT
. How do i get a file object from a content uri, i am unable to get even a file path from a Content Uri
. And if i dont have the file path, i cant get a file object.
This was the method that i was using to get the file path from a content uri.
public String getPDFPath(Uri uri) {
final String id = DocumentsContract.getDocumentId(uri);
final Uri contentUri = ContentUris.withAppendedId(
uri, Long.valueOf(id));
String[] projection = {
MediaStore.Images.Media.DATA
};
Cursor cursor = getContentResolver().query(contentUri, projection, null, null, null);
int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
cursor.moveToFirst();
return cursor.getString(column_index);
}