I'm using the okhttp library in android to upload files to the server. I used to get the real path of the file from the URI returned by the Storage Access Framework then upload it.
In android 11, I'm able to get the real path of Media files but for non media files like documents "content://com.android.providers.media.documents/document/documentXX" I get a null path. "content://com.android.providers.media.documents/document/imageXX" will works fine by returning /storage/emulated/0/Download/xxx.jpeg
Can someone please provide me the way to get documents real path in android 11? or if there is another way of uploading the documents without the need of getting the real path.
Thanks,
String path = FileUtils.getPath(this, uri);//Get the absolute path of the file through uri
File file = new File(path);//Create a specific file class
String fileName = file.getName();//To get the file name is mainly the suffix of the file name
String type = getContentResolver().getType(uri);
RequestBody requestBody = RequestBody.create(file, MediaType.parse(type));
...