I think I'm doing everything right to first create a folder that I can write to later in my app, but it doesn't seem to be working. Any clues as to how I've failed?
It correctly tries to create /mnt/sdcard/gradebook
I have uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" in my manifest. I'm running on a real device (Samsung Galaxy S) and I'm not using the sdcard as storage while its attached to my computer.
boolean mExternalStorageAvailable = false;
boolean mExternalStorageWriteable = false;
String state = Environment.getExternalStorageState();
if (Environment.MEDIA_MOUNTED.equals(state)) {
// We can read and write the media
mExternalStorageAvailable = mExternalStorageWriteable = true;
} else if (Environment.MEDIA_MOUNTED_READ_ONLY.equals(state)) {
// We can only read the media
mExternalStorageAvailable = true;
mExternalStorageWriteable = false;
Toast.makeText(this,"This Application needs a writable external storage (sdcard).",Toast.LENGTH_SHORT).show();
finish();
} else {
// Something else is wrong. It may be one of many other states, but all we need
// to know is we can neither read nor write
mExternalStorageAvailable = mExternalStorageWriteable = false;
Toast.makeText(this,"This Application needs a mounted external storage (sdcard).",Toast.LENGTH_SHORT).show();
finish();
}
File folder = new File(Environment.getExternalStorageDirectory () + "/gradeBook");
boolean success = false;
if(!folder.exists()){
success = folder.mkdir();
}
if (!success) {
Log.e("FILE", "can't create " + folder);
}
else
{
Log.i("FILE", "directory is created");
}
Here is the manifest
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.ulsanonline.gradebook"
android:versionName="@string/version"
android:installLocation="auto"
android:versionCode="2">
<uses-sdk android:minSdkVersion="8"></uses-sdk>
<application
android:icon="@drawable/icon"
android:debuggable="true"
android:persistent="false"
android:hasCode="true"
android:minSdkVersion="8">
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.CAMERA" />
<activity
android:name=".CourseWork"
android:label="@string/app_name"
android:screenOrientation="portrait">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
uses-permission
must be placed directly as <manifest>
child, so it should be:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.ulsanonline.gradebook"
android:versionName="@string/version"
android:installLocation="auto"
android:versionCode="2">
<uses-sdk android:minSdkVersion="8"></uses-sdk>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.CAMERA" />
<application
android:icon="@drawable/icon"
android:debuggable="true"
android:persistent="false"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With