Actually, I made a mistake.  If I have the "uses-sdk" in the manifest,
no matter what the value, it fails to create the directory.  I do have
the write_external_storage permission.

The code used to work until I upgraded the SDK to 2.1 I think.  This
used to work till around 2.0 of the sdk.

If I create the directory under data/data using
    File basedirectory = getFileStreamPath("basedir");
    subdirectory = new File( basedirectory, "subdir_0/subdir_1" );
but I don't want the directory to be deleted when the app is
uninstalled.

The manifest file is as under.

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android";
          package="test.test"
          android:versionCode="1"
          android:versionName="1.0">

        <uses-sdk android:minSdkVersion="4"/>
    <uses-permission-group android:name="android.permission-
group.STORAGE" />

    <application android:icon="@drawable/icon"
                         android:label="@string/app_name">

        <activity android:name=".Test1"
                  android:label="@string/app_name">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category
android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>

    </application>

</manifest>

On Sep 12, 2:41 am, Mark Murphy <[email protected]> wrote:
> Do you have the WRITE_EXTERNAL_STORAGE permission?
>
>
>
> On Sat, Sep 11, 2010 at 5:24 PM, milind <[email protected]> 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/commonsguyhttp://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 [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to