0

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.

duggu
  • 37,851
  • 12
  • 116
  • 113
Matt
  • 5,461
  • 7
  • 36
  • 43
  • I think for API 8 and up you should use getExternalFilesDir() instead of getExternalStorageDirectory() – jkhouw1 Jun 02 '11 at 18:30
  • Well it's not an issue of the path being correct, because I can read from the Xoom's storage, just not write to it. – Matt Jun 02 '11 at 19:03
  • "The Xoom does not have a working SD slot, so Moto decided to re-route calls to External Storage to the internal storage" -- this is not unique to the XOOM. I'd estimate 20% of Android devices have no SD card slot. "External" does not mean "removable", but "accessible from a host PC". "This code creates a folder on my Droid's SD card, but not on my Xoom's storage" -- based on the code listing you have here, you are trying to create a directory that already exists, since `path` exists. Consider posting a more complete source listing if that is not what you are actually doing. – CommonsWare Jun 02 '11 at 20:00
  • You're right, I edited the post to show that I am trying to add a new folder – Matt Jun 03 '11 at 13:45

2 Answers2

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"/>
stk
  • 6,311
  • 11
  • 42
  • 58
  • Well, after I try this code, path.isDirectory() does in fact return true. However, the folder does not show up when I browse the storage on my computer. I have tried restarting the xoom and the folder still does not show up, but still says it is there according to path.isDirectory() – Matt Jun 03 '11 at 17:50
  • I was able to eventually see the folder through My Computer after some combination of restarting the Xoom, unplugging it and plugging it back in. It seems the actual problem lies somewhere else – Matt Jun 03 '11 at 18:07
0

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"/>
Sayyam
  • 959
  • 10
  • 22