I wrote some code to save images on the SD Card a while back. Now I added the targetSDKVersion to my manifest and now my file saving code ceased to work.
I can reproduce it through removing the targetSdkVersion from my manifest from that on my App won't write anything to the SD Card.
Is there an API change between Android 1.5 and 1.6 that prevents me from writing to the SD-Card?
File imageDirectory = new File(Environment.getExternalStorageDirectory()
.getAbsolutePath()
+ File.separator
+ FOLDER_NAME);
Log.d(ImageSaver.class.getSimpleName(), "SD Card status: "
+ Environment.getExternalStorageState());
if (!imageDirectory.exists()) {
boolean created = imageDirectory.mkdir();
Log.d(ImageSaver.class.getSimpleName(), "Created image directory "
+ imageDirectory + " " + created);
}
File imageFile = new File(imageDirectory.getAbsolutePath() + File.separator
+ name + nameSuffix + FILE_ENDING);
bitmap.compress(Bitmap.CompressFormat.PNG, FULL_QUALITY,
new FileOutputStream(imageFile));
This is the test code for compressing an bitmap to the SD Card. With the following manifest entry it does not work:
<uses-sdk
android:minSdkVersion="3"
android:targetSdkVersion="8" />
I get the following exception:
09-27 11:35:58.689: ERROR/ImageSaver(8672): File not found 09-27 11:35:58.689: ERROR/ImageSaver(8672): java.io.FileNotFoundException: /sdcard/FOLDER/1285580158662.png
Removing the targetSdkVersion makes it work on all platforms again.
How can I make the code run with the targetSdkVersion set?