I think this is the problem: Uri uri = getContentResolver().insert(Media.EXTERNAL_CONTENT_URI, values);
The first parameter of 'insert' must either be a bitmap or the path to an actual image-file. Right now, you provide the value Media.EXTERNAL_CONTENT_URI, which is a directory, not a file. E.g., i think this would work ok: Bitmap sourceBitmap = BitmapFactory.decodeResource(getResources(), R.drawable.test); Uri uri = getContentResolver().insert(sourceBitmap, values); Or First create an empty file in the directory Media.EXTERNAL_CONTENT_URI and provide the full path of this file for the insert method. On Aug 26, 5:58 am, Dany BREARD <[email protected]> wrote: > I try to make everything to fix that but its too complicated !!! > > If somebody has a solution, please help me I'm sure its very > simply !!! > > On Aug 26, 10:01 am, Dany BREARD <[email protected]> wrote: > > > > > Hi > > > I change EXTERNAL_CONTENT_URI to INTERNAL_CONTENT_URI, and I have an > > other error that I can't Fix : > > > 08-26 07:49:39.084: ERROR/DatabaseUtils(648): Writing exception to > > parcel > > 08-26 07:49:39.084: ERROR/DatabaseUtils(648): > > java.lang.UnsupportedOperationException: Writing to internal storage > > is not supported. > > 08-26 07:49:39.084: ERROR/DatabaseUtils(648): at > > com.android.providers.media.MediaProvider.generateFileName > > (MediaProvider.java:1346) > > 08-26 07:49:39.084: ERROR/DatabaseUtils(648): at > > com.android.providers.media.MediaProvider.ensureFile > > (MediaProvider.java:1074) > > 08-26 07:49:39.084: ERROR/DatabaseUtils(648): at > > com.android.providers.media.MediaProvider.insertInternal > > (MediaProvider.java:1150) > > 08-26 07:49:39.084: ERROR/DatabaseUtils(648): at > > com.android.providers.media.MediaProvider.insert(MediaProvider.java: > > 1118) > > 08-26 07:49:39.084: ERROR/DatabaseUtils(648): at > > android.content.ContentProvider$Transport.insert(ContentProvider.java: > > 140) > > 08-26 07:49:39.084: ERROR/DatabaseUtils(648): at > > android.content.ContentProviderNative.onTransact > > (ContentProviderNative.java:125) > > 08-26 07:49:39.084: ERROR/DatabaseUtils(648): at > > android.os.Binder.execTransact(Binder.java:287) > > 08-26 07:49:39.084: ERROR/DatabaseUtils(648): at > > dalvik.system.NativeStart.run(Native Method) > > 08-26 07:49:39.114: DEBUG/AndroidRuntime(779): Shutting down VM > > 08-26 07:49:39.124: WARN/dalvikvm(779): threadid=3: thread exiting > > with uncaught exception (group=0x4000fe70) > > 08-26 07:49:39.124: ERROR/AndroidRuntime(779): Uncaught handler: > > thread main exiting due to uncaught exception > > 08-26 07:49:39.154: ERROR/AndroidRuntime(779): > > java.lang.RuntimeException: Unable to start activity ComponentInfo > > {dany.android.databasejpeg/dany.android.databasejpeg.testjpeg}: > > java.lang.UnsupportedOperationException: Writing to internal storage > > is not supported. > > 08-26 07:49:39.154: ERROR/AndroidRuntime(779): at > > android.app.ActivityThread.performLaunchActivity(ActivityThread.java: > > 2268) > > 08-26 07:49:39.154: ERROR/AndroidRuntime(779): at > > android.app.ActivityThread.handleLaunchActivity(ActivityThread.java: > > 2284) > > 08-26 07:49:39.154: ERROR/AndroidRuntime(779): at > > android.app.ActivityThread.access$1800(ActivityThread.java:112) > > 08-26 07:49:39.154: ERROR/AndroidRuntime(779): at > > android.app.ActivityThread$H.handleMessage(ActivityThread.java:1692) > > 08-26 07:49:39.154: ERROR/AndroidRuntime(779): at > > android.os.Handler.dispatchMessage(Handler.java:99) > > 08-26 07:49:39.154: ERROR/AndroidRuntime(779): at > > android.os.Looper.loop(Looper.java:123) > > 08-26 07:49:39.154: ERROR/AndroidRuntime(779): at > > android.app.ActivityThread.main(ActivityThread.java:3948) > > 08-26 07:49:39.154: ERROR/AndroidRuntime(779): at > > java.lang.reflect.Method.invokeNative(Native Method) > > 08-26 07:49:39.154: ERROR/AndroidRuntime(779): at > > java.lang.reflect.Method.invoke(Method.java:521) > > 08-26 07:49:39.154: ERROR/AndroidRuntime(779): at > > com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run > > (ZygoteInit.java:782) > > 08-26 07:49:39.154: ERROR/AndroidRuntime(779): at > > com.android.internal.os.ZygoteInit.main(ZygoteInit.java:540) > > 08-26 07:49:39.154: ERROR/AndroidRuntime(779): at > > dalvik.system.NativeStart.main(Native Method) > > 08-26 07:49:39.154: ERROR/AndroidRuntime(779): Caused by: > > java.lang.UnsupportedOperationException: Writing to internal storage > > is not supported. > > 08-26 07:49:39.154: ERROR/AndroidRuntime(779): at > > android.database.DatabaseUtils.readExceptionFromParcel > > (DatabaseUtils.java:131) > > 08-26 07:49:39.154: ERROR/AndroidRuntime(779): at > > android.database.DatabaseUtils.readExceptionFromParcel > > (DatabaseUtils.java:111) > > 08-26 07:49:39.154: ERROR/AndroidRuntime(779): at > > android.content.ContentProviderProxy.insert(ContentProviderNative.java: > > 340) > > 08-26 07:49:39.154: ERROR/AndroidRuntime(779): at > > android.content.ContentResolver.insert(ContentResolver.java:476) > > 08-26 07:49:39.154: ERROR/AndroidRuntime(779): at > > dany.android.databasejpeg.testjpeg.onCreate(testjpeg.java:35) > > 08-26 07:49:39.154: ERROR/AndroidRuntime(779): at > > android.app.Instrumentation.callActivityOnCreate(Instrumentation.java: > > 1123) > > 08-26 07:49:39.154: ERROR/AndroidRuntime(779): at > > android.app.ActivityThread.performLaunchActivity(ActivityThread.java: > > 2231) > > 08-26 07:49:39.154: ERROR/AndroidRuntime(779): ... 11 more > > > On Aug 25, 9:17 am, Dany BREARD <[email protected]> wrote: > > > > Hi > > > > Why I have this error, please ? It' s the same java code than the > > > following url: > > > >http://developer.android.com/intl/fr/guide/topics/providers/content-p... > > > > / > > > ****************************************************************************/ > > > > package dany.android.databasejpeg; > > > > import java.io.OutputStream; > > > > import android.app.Activity; > > > import android.content.ContentValues; > > > import android.graphics.Bitmap; > > > import android.graphics.BitmapFactory; > > > import android.net.Uri; > > > import android.os.Bundle; > > > import android.provider.MediaStore.Images.Media; > > > import android.util.Log; > > > > public class testjpeg extends Activity { > > > private static final String TAG = null; > > > > /** Called when the activity is first created. */ > > > @Override > > > public void onCreate(Bundle savedInstanceState) { > > > super.onCreate(savedInstanceState); > > > setContentView(R.layout.main); > > > > // Save the name and description of an image in a ContentValues > > > map. > > > ContentValues values = new ContentValues(3); > > > values.put(Media.DISPLAY_NAME, "road_trip_1"); > > > values.put(Media.DESCRIPTION, "Day 1, trip to Los Angeles"); > > > values.put(Media.MIME_TYPE, "image/jpeg"); > > > > // Add a new record without the bitmap, but with the values > > > just set. > > > // insert() returns the URI of the new record. > > > > Log.v(TAG, Media.EXTERNAL_CONTENT_URI.toString()); > > > > Uri uri = getContentResolver().insert > > > (Media.EXTERNAL_CONTENT_URI, values); > > > > // Now get a handle to the file for that record, and save the > > > data into it. > > > // Here, sourceBitmap is a Bitmap object representing the file > > > to save to the database. > > > > Bitmap sourceBitmap = BitmapFactory.decodeResource(getResources > > > (), R.drawable.test); > > > > try { > > > OutputStream outStream = getContentResolver > > > ().openOutputStream(uri); > > > sourceBitmap.compress(Bitmap.CompressFormat.JPEG, 50, > > > outStream); > > > outStream.close(); > > > } catch (Exception e) { > > > Log.e(TAG, "exception while writing image: ", e); > > > } > > > }} > > > > / > > > ****************************************************************************/ > > > > 08-25 07:08:09.507: ERROR/DatabaseUtils(656): Writing exception to > > > parcel > > > 08-25 07:08:09.507: ERROR/DatabaseUtils(656): > > > java.lang.UnsupportedOperationException: Unknown URI: > > > content://media/external/images/media > > > 08-25 07:08:09.507: ERROR/DatabaseUtils(656): at > > > com.android.providers.media.MediaProvider.insertInternal > > > (MediaProvider.java:1139) > > > 08-25 07:08:09.507: ERROR/DatabaseUtils(656): at > > > com.android.providers.media.MediaProvider.insert(MediaProvider.java: > > > 1118) > > > 08-25 07:08:09.507: ERROR/DatabaseUtils(656): at > > > android.content.ContentProvider$Transport.insert(ContentProvider.java: > > > 140) > > > 08-25 07:08:09.507: ERROR/DatabaseUtils(656): at > > > android.content.ContentProviderNative.onTransact > > > (ContentProviderNative.java:125) > > > 08-25 07:08:09.507: ERROR/DatabaseUtils(656): at > > > android.os.Binder.execTransact(Binder.java:287) > > > 08-25 07:08:09.507: ERROR/DatabaseUtils(656): at > > > dalvik.system.NativeStart.run(Native Method) > > > 08-25 07:08:09.536: DEBUG/AndroidRuntime(735): Shutting down VM > > > 08-25 07:08:09.536: WARN/dalvikvm(735): threadid=3: thread exiting > > > with uncaught exception (group=0x4000fe70) > > > 08-25 07:08:09.536: ERROR/AndroidRuntime(735): Uncaught handler: > > > thread main exiting due to uncaught exception > > > 08-25 07:08:09.546: ERROR/AndroidRuntime(735): > > > java.lang.RuntimeException: Unable to start activity ComponentInfo > > > {dany.android.databasejpeg/dany.android.databasejpeg.testjpeg}: > > > java.lang.UnsupportedOperationException: Unknown URI: > > > content://media/external/images/media > > > 08-25 07:08:09.546: ERROR/AndroidRuntime(735): at > > > android.app.ActivityThread.performLaunchActivity(ActivityThread.java: > > > 2268) > > > 08-25 07:08:09.546: ERROR/AndroidRuntime(735): at > > > android.app.ActivityThread.handleLaunchActivity(ActivityThread.java: > > > 2284) > > > 08-25 07:08:09.546: ERROR/AndroidRuntime(735): at > > > android.app.ActivityThread.access$1800(ActivityThread.java:112) > > > 08-25 07:08:09.546: ERROR/AndroidRuntime(735): at > > > android.app.ActivityThread$H.handleMessage(ActivityThread.java:1692) > > > 08-25 07:08:09.546: ERROR/AndroidRuntime(735): at > > > android.os.Handler.dispatchMessage(Handler.java:99) > > > 08-25 07:08:09.546: ERROR/AndroidRuntime(735): at > > > android.os.Looper.loop(Looper.java:123) > > > 08-25 07:08:09.546: ERROR/AndroidRuntime(735): at- Hide quoted text - > > - Show quoted text -... > > read more » --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---

