-3

I am using following method to set my working Directory

 File file = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES), "xxxxxx");

Now the problem is that this gives me variable location in case of phones with multiple Sdcards. Sometimes, it automatically gives me External Sd card as default location but in Some phones like Samsung, it always gives me Internal SdCard as default location i.e. storage/sdcard0/Pictures/xxxxxxx. What i want is storage/extsdcard/Pictures/xxxxxxx. But i don't wanna hardcode the path. And also, i have heard that in Kitkat version, it is not possible to put files in external Sdcard. So How do i deal with Both the problems?

Note: I tried changing the default Storage Location in Samsung to External SdCard but it doesn't worked out.

1 Answers1

0

Depending on your API requirements have you tried using this:

API level 8+

Context.getExternalFilesDirs()

API level 7-

Context.getExternalStorageDirectory();

maybe the problem is that you are running this on device (or simulator) with API 8 or higher then you need to use the first approach. If your app should support APIs lower than 8 then I suggest you do if then statement to check actual API version like this:

if (Build.VERSION.SDK_INT >= 8) {
    Context.getExternalFilesDirs()
}else{
    Context.getExternalStorageDirectory();
}
horin
  • 1,664
  • 6
  • 23
  • 52
  • Ok, I will Check it soon. And Do You have any Info on creating new files in External SD Card in Kitkat Version? – Sagar Mehar Feb 06 '16 at 20:04
  • try checking this answer http://stackoverflow.com/questions/5625315/how-to-create-a-file-in-an-sdcard-directory – horin Feb 06 '16 at 20:08