-->

Creating a folder programmatically on a Xoom

2019-08-22 04:30发布

问题:

The Xoom does not have a working SD slot, so Moto decided to re-route calls to External Storage to the internal storage:

String path = Environment.getExternalStorageDirectory().getPath() + "/newfolder/";

The above line returns a path to the Internal storage on the Xoom, and to the SD card on my Droid.

However, I am having trouble writing to this path on a Xoom. It's as if it is write protected, or I do not have permission.

This code creates a folder on my Droid's SD card, but not on my Xoom's storage:

File file = new File(path);
file.mkdir();

One thought was that since the Xoom is only "faking" that it is external storage, maybe the app needs the "internal storage" permission as well, but that did not fix it.

回答1:

on my xoom it´s working like this:

    private File path;
    path = new File(Environment.getExternalStorageDirectory().toString() + "/audio");
    path.mkdirs();

mkdirs (with ending s), because then missing dirs on the way to the end-path are automatically created.

are you sure you´re having this in your AndroidManifest?

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


回答2:

I was having same problem in my Nexus S running android 2.3.4, after playing around with stk's code I was able to create a folder.

Here is the final code:

File root = new File(Environment.getExternalStorageDirectory().toString()+"//MyFolder");
root.mkdirs();

Simply replaced "/audio" with "//audio" in stk's code and it worked for me.

You should have write permission in your AndroidManifest under tag.

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