0

I am trying to create a new file using getExternalFilesDir(Environment.DIRECTORY_PICTURES) but it is returning null. When I run Environment.getExternalStorageState() it is currently returning removed. This is currently only the case for Ice Cream Sandwich and Jelly Bean, as I have tested both Marshmallow and Nougat and it works fine. I am using an Emulator, how would I fix this?

Edit: I have also included read and write permissions in the Manifest. (read and write external storage)

Xh Lin
  • 666
  • 1
  • 6
  • 21

2 Answers2

0

Do you add these permissions to manifest?

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

From docs of getExternalFilesDir():

May return null if shared storage is not currently available.

Which means, you have to check weather storage is mounter or no via getExternalStorageState(File).

Shared storage may not always be available, since removable media can be ejected by the user. Media state can be checked using getExternalStorageState(File).

Community
  • 1
  • 1
azizbekian
  • 60,783
  • 13
  • 169
  • 249