iPaulPro / aFileChooser

[DEPRECATED] Android library that provides a file explorer to let users select files on external storage.
Apache License 2.0
1.79k stars 850 forks source link

Issue getting path from file located on SD card #54

Open j-roskopf opened 9 years ago

j-roskopf commented 9 years ago

When using the aFileChooserExample application, I will select a file located on my SD card, and the resulting toast says "File Selected: null". Is there something I have to do to properly retrieve the path from the SD card?

nicolabeghin commented 9 years ago

I'm interested in this too. Works flawlessly but sometimes behaves like @j-roskopf wrote. I get

11-05 15:27:47.820 I/MyApp(22768): onPause 11-05 15:27:47.860 I/Timeline(22768): Timeline: Activity_launch_request id:com.android.documentsui time:99395512 11-05 15:27:47.860 W/ResourceType(22768): CREATING STRING CACHE OF 44 bytes 11-05 15:27:50.250 W/MyApp(22768): content://com.android.externalstorage.documents/document/3037-6461%3Afile.txt

Maybe the

content://com.android.externalstorage.documents/document/3037-6461%3AChatStorage.sqlite is not treated in the right way?

I think the error lies in FileUtils.getPath:

public static String getPath(final Context context, final Uri uri) 

Any hint whatsoever?

thanks nicola

j-roskopf commented 9 years ago

Hello. I believe I have found the error, in case you were still looking for it. In 4.4 and above, file access to the SD card is restricted, so I don't believe it to be a bug with the code

xandebianchi commented 8 years ago

I did a modification in function getPath, FileUtils.java. It could solve the problem. I propose to solution and up it.

... if ("primary".equalsIgnoreCase(type)) { return Environment.getExternalStorageDirectory() + "/" + split[1]; } else { String strPath; if (Environment.isExternalStorageRemovable()){ strPath = System.getenv("EXTERNAL_STORAGE"); } else{ strPath = System.getenv("SECONDARY_STORAGE"); if (strPath == null || strPath.length() == 0) { strPath = System.getenv("EXTERNAL_SDCARD_STORAGE"); } } ...