Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
el-Knix opened this issue Oct 27, 2021 · 10 comments
Closed
Assignees
Labels
Bug Something isn't working Fixed

Comments

@el-Knix
Copy link

el-Knix commented Oct 27, 2021

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
@HBiSoft
Copy link
Owner

HBiSoft commented Oct 28, 2021

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

@HBiSoft HBiSoft added the Needs more info More information is needed to be able to fix the issue label Oct 28, 2021
@el-Knix
Copy link
Author

el-Knix commented Oct 28, 2021

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.

@Ammarulhaq
Copy link

@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

@HBiSoft
Copy link
Owner

HBiSoft commented Oct 31, 2021

@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"

@el-Knix
Copy link
Author

el-Knix commented Oct 31, 2021

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

@HBiSoft
Copy link
Owner

HBiSoft commented Nov 5, 2021

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.

@el-Knix
Copy link
Author

el-Knix commented Nov 9, 2021

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

@HBiSoft
Copy link
Owner

HBiSoft commented Nov 10, 2021

@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.

@el-Knix
Copy link
Author

el-Knix commented Nov 10, 2021

@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?

@HBiSoft
Copy link
Owner

HBiSoft commented Nov 10, 2021

@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;
}

@HBiSoft HBiSoft closed this as completed Nov 10, 2021
@HBiSoft HBiSoft added Bug Something isn't working Fixed and removed Needs more info More information is needed to be able to fix the issue labels Nov 10, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Something isn't working Fixed
Projects
None yet
Development

No branches or pull requests

3 participants