HBiSoft / PickiT

An Android library that returns real paths from Uri's

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Picking a file from a subfolder inside downloads folder returns wrong path

el-Knix opened this issue · comments

Describe the bug
If you select a file that is inside a subfolder inside the downloads tab, pickit returns path of the file without the subfolder name.

Can it be reproduced in demo app
Yes

PickiT version
0.1.14

Device information

  • Huawei Mate 20 Pro
  • 29

Please provide a screenshot of the demo application after selecting a file in a subfolder in Downloads.

4
1
2
3

The path returned by pickit throws a File Not Found Exception. Expected the Path returned to be /storage/emulated/0/Download/Adele/00 Test.mp3.

Screenshots taken from an emulator but the error still occurs even on a real device .Api Level of the device is 29 but the error also occurs on api 30.

@el-Knix I think this issue is not about pickIt SDK. I'd the same issue what actually happens is when we use download file function path is reference to "Download" directory what i did was i just point my directory to "Download/MY_FOLDER_NAME" and it worked

@el-Knix
I was able to reproduce this. The only way I can work around this is to check for the msf: protocol and copy the file to your apps directly.

@Ammarulhaq
Can you please elaborate on what you mean with:

i just point my directory to "Download/MY_FOLDER_NAME"

@HBiSoft That's the work around I'm currently using. Not ideal but I guess there's no choice.

I've made the necessary changes and will implement it into the library tomorrow.

It will now first check for the msf: protocol, then check if the file is available in the Downloads directory, if not it means it's in a subdirectory inside the Downloads directory and gets copied into the applications directory.

I will keep looking for ways to do it without copying the file, but in the meantime this will have to suffice.

Thanks Mate that will have to do...Great work on the library!

@el-Knix
My apologies for the delay.

I have found a way to get the path without having to copy it, by using /proc/.
I have tested it on multiple devices, but it would be great if you can test it as well.

The latest release (2.0.1) is available here.


Please close the issue after you have tested it.

@HBiSoft
Just tested, seems to work great kudos.

Just one issue, the filename seems to be lost with this method since the proc path only has a number. Any idea on how we can get the filename from the /proc/ path?

@el-Knix
You will have to make use of the original Uri that gets returned from MediaStore.

Here's how I do it inside the library:

private String getFileName(Uri uri, Context context) {
String result = null;
if (uri.getScheme() != null) {
if (uri.getScheme().equals("content")) {
Cursor cursor = context.getContentResolver().query(uri, null, null, null, null);
if (cursor != null && cursor.moveToFirst()) {
result = cursor.getString(cursor.getColumnIndex(OpenableColumns.DISPLAY_NAME));
}
if (cursor != null) {
cursor.close();
}
}
}
if (result == null) {
result = uri.getPath();
assert result != null;
int cut = result.lastIndexOf('/');
if (cut != -1) {
result = result.substring(cut + 1);
}
}
return result;
}