Hi,

 I am trying to store an image in phone memory /data/data/com.myapp/
files/here.jpeg but I keep getting an exception. If I try to store the
image using the normal 'FileOutputStream' it works fine. Can anyone
point out what am I doing wrong? I want to store an image in my phone
memory app folder so that when user is setting wallpaper the image can
be listed in 'gallery'. I do not want to store the image on sdcard.

 The same code works fine if I store the image in sdcard, only thing I
change is EXTERNAL_CONTENT_URI

ContentValues values = new ContentValues();
                values.put(MediaStore.MediaColumns.DATA, outPath);
                values.put(MediaStore.MediaColumns.TITLE, "testing1");
                values.put(MediaStore.MediaColumns.SIZE, file.length());
                values.put(MediaStore.MediaColumns.MIME_TYPE, "image/jpeg");


                Uri uri =
context.getContentResolver().insert(android.provider.MediaStore.Images.Media.INTERNAL_CONTENT_URI,
values);

                Bitmap sourceBitmap = BitmapFactory.decodeByteArray(data, 0,
data.length);

                try {
                    OutputStream outStream =
context.getContentResolver().openOutputStream(uri);
                    sourceBitmap.compress(Bitmap.CompressFormat.JPEG, 50,
outStream);
                    outStream.close();
                } catch (Exception e) {
                    Logger.d("exception while writing image: ");
                }

The exception I am getting is:

02-23 05:56:30.036: ERROR/MediaProvider(188): File creation failed
02-23 05:56:30.036: ERROR/MediaProvider(188): java.io.IOException:
Parent directory of file is not writable: /data/data/com.myapp/files/
somefile.jpeg
02-23 05:56:30.036: ERROR/MediaProvider(188):     at
java.io.File.createNewFile(File.java:1263)
02-23 05:56:30.036: ERROR/MediaProvider(188):     at
com.android.providers.media.MediaProvider.ensureFileExists(MediaProvider.java:
1670)
02-23 05:56:30.036: ERROR/MediaProvider(188):     at
com.android.providers.media.MediaProvider.ensureFile(MediaProvider.java:
1344)
02-23 05:56:30.036: ERROR/MediaProvider(188):     at
com.android.providers.media.MediaProvider.insertInternal(MediaProvider.java:
1413)
02-23 05:56:30.036: ERROR/MediaProvider(188):     at
com.android.providers.media.MediaProvider.insert(MediaProvider.java:
1381)
02-23 05:56:30.036: ERROR/MediaProvider(188):     at
android.content.ContentProvider$Transport.insert(ContentProvider.java:
150)
02-23 05:56:30.036: ERROR/MediaProvider(188):     at
android.content.ContentProviderNative.onTransact(ContentProviderNative.java:
140)
02-23 05:56:30.036: ERROR/MediaProvider(188):     at
android.os.Binder.execTransact(Binder.java:287)
02-23 05:56:30.036: ERROR/MediaProvider(188):     at
dalvik.system.NativeStart.run(Native Method)
02-23 05:56:30.066: ERROR/DatabaseUtils(188): Writing exception to
parcel
02-23 05:56:30.066: ERROR/DatabaseUtils(188):
java.lang.IllegalStateException: Unable to create new file: /data/data/
com.myapp/files/somefile.jpeg
02-23 05:56:30.066: ERROR/DatabaseUtils(188):     at
com.android.providers.media.MediaProvider.ensureFile(MediaProvider.java:
1345)
02-23 05:56:30.066: ERROR/DatabaseUtils(188):     at
com.android.providers.media.MediaProvider.insertInternal(MediaProvider.java:
1413)
02-23 05:56:30.066: ERROR/DatabaseUtils(188):     at
com.android.providers.media.MediaProvider.insert(MediaProvider.java:
1381)
02-23 05:56:30.066: ERROR/DatabaseUtils(188):     at
android.content.ContentProvider$Transport.insert(ContentProvider.java:
150)
02-23 05:56:30.066: ERROR/DatabaseUtils(188):     at
android.content.ContentProviderNative.onTransact(ContentProviderNative.java:
140)
02-23 05:56:30.066: ERROR/DatabaseUtils(188):     at
android.os.Binder.execTransact(Binder.java:287)
02-23 05:56:30.066: ERROR/DatabaseUtils(188):     at
dalvik.system.NativeStart.run(Native Method)

-- 
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