Do you have the WRITE_EXTERNAL_STORAGE permission?
On Sat, Sep 11, 2010 at 5:24 PM, milind wrote:
> The following code works when I either have no min sdk version
> specified in the app manifest or if it's 5 or greater. But if I set
> the min sdk level to 4 (Android 1.6) , it fails to create a
> subdirectory in the sdcard. There is no error. mkdir() or mkdirs()
> just returns false.
>
> String msg;
> try {
> String theState = Environment.getExternalStorageState();
> if (theState.equals(Environment.MEDIA_MOUNTED)) {
> File theBasedir =
> Environment.getExternalStorageDirectory();
> File theSubdir = new File(theBasedir, "subdir");
> boolean created = theSubdir.mkdirs();
> msg = theSubdir.exists() ? "Success" : "Fail";
> } else {
> msg = "Invalid State";
> }
> } catch (Exception e) {
> msg = "Error - " + e;
> }
> System.out.println(msg);
>
> Am I doing something wrong here? Or is this a bug? I'd prefer not to
> set the target to 2.1 and min version to 1.6. But right now, I have
> to set it to 2.0 for it to work.
--
Mark Murphy (a Commons Guy)
http://commonsware.com | http://github.com/commonsguy
http://commonsware.com/blog | http://twitter.com/commonsguy
Android 2.2 Programming Books: http://commonsware.com/books
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en