Home Ask Login Register

Developers Planet

Your answer is one click away!

Sagar Mehar February 2016

How Can i change The Default Location Of My Working Directory?

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.

Answers


horin February 2016

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();
}

Post Status

Asked in February 2016
Viewed 3,865 times
Voted 11
Answered 1 times

Search




Leave an answer


Quote of the day: live life