Skip to content Skip to sidebar Skip to footer

Android Kitkat 4.4 Folder On Sd Card

We've just fallen foul of the new permissions that apply to writing files to sd cards (external storage) on Android 4.4 (EACCES Permission Denied) Prior to KitKat we set our writab

Solution 1:

Updated solution.

This sets and also creates the folder in the correct place for KitKat.

mfolder = this.getExternalFilesDir("asubfoldername").getAbsolutePath();

However, this isn't full-proof, if the Android device has both an internal and external secondary storage locations, the above will use the internal one. Not really what we want as we require path to removable sdcard or better still the path to the secondary storagelocation with the most free available space.

File[] possible_kitkat_mounts = getExternalFilesDirs(null);

Note the "s" on the end of getExternalFilesDirs. This creates an array of secondary external storage locations.

for (int x = 0; x < possible_kitkat_mounts.length; x++) {
    //Log.d("test", "possible_kitkat_mounts " + possible_kitkat_mounts[x].toString());
    boolean isgood=false;
    if (possible_kitkat_mounts[x] != null){
        isgood = test_mount(possible_kitkat_mounts[x].toString());  
        if (isgood==true){
            arrMyMounts.add(newymounts(Device_get_device_info(possible_kitkat_mounts[x].toString()), possible_kitkat_mounts[x].toString()));
        }   
    }
}                           

//sort arrMyMounts size so we can use largest
Collections.sort(arrMyMounts, new Comparator<mymounts>(){
    publicintcompare(mymounts obj1, mymounts obj2){
        return (obj1.avaliablesize > obj2.avaliablesize) ? -1: (obj1.avaliablesize > obj2.avaliablesize) ? 1:0 ;
    }
}); 


if (arrMyMounts.size()>0){
    mfolder = arrMyMounts.get(0).name + "/asubfoldername";
    //Log.d("test", "selected kitkat mount " + kitkatfolder);   
}else{
    //do something else...
}

From the array of possible_kitkat_mounts we check via test_mount to see if we can actually write to the selected location and if successful we add that location to arrMyMounts.

By sorting arrMyMounts we can then get the location with the most available free space.

Hey presto, arrMyMounts.get(0).name is a kitkat secondary storage location with the most free space.

Solution 2:

Google has blocked write access to external storage devices in Android 4.4. Until they change it there is no way to revert it back without root.

More info: https://groups.google.com/forum/#!msg/android-platform/14VUiIgwUjY/UsxMYwu02z0J

It might be working on some devices with Kitkat which have minisd card slot. It is confusing :(

Post a Comment for "Android Kitkat 4.4 Folder On Sd Card"