Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

getExternalFilesdir Fail

OnActivityCreated I'm doing:

activity.getExternalFilesDir(Environment.DIRECTORY_PICTURES);

In logcat I get:

com.package W/ContextImpl﹕ Failed to ensure directory: /storage/sdcard1/Android/data/com.package/files/Pictures

This happens only on LOLLIPOP (MOTO G 2014), and everything is fine on KITKAT (Nexus 4). I've WRITE_EXTERNAL_STORAGE on manifest. What am I missing here? The storage is mounted and reachable via a file browsing app (like ES Explorer).

EDIT: Surprisingly the file is correctly created under the directory even if I get the warning reported above.

like image 864
Jumpa Avatar asked Aug 05 '15 11:08

Jumpa


1 Answers

Try this :

String path = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES);

and use this permission:

<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />

Actually:

getExternalFilesDir()

It returns the path to files folder inside /Android/data/com.package/files/Pictures on your SD card. And there is no folder named Pictures inside it. So you are getting that error.

like image 151
Anand Singh Avatar answered Sep 18 '22 19:09

Anand Singh