I encountered the same issue. I took me looooong time to figure out what was going wrong. I solved it by running it through the mediascanner.
[code snippet] // I have the jpg-data from the onPictureTaken callback in 'mJPGData': final Bitmap pic = BitmapFactory.decodeByteArray(mJPGData, 0, mJPGData.length, picOptions); mJPGData = null; final String strUri = MediaStore.Images.Media.insertImage (getContentResolver(), pic, "", ""); if (strUri == null) { // show error message. } ... ... final Uri imgUri = Uri.parse(strUri); android.database.Cursor cur = null; cur = getContentResolver().query( imgUri, new String[] { MediaStore.Images.ImageColumns.DATA }, null, null, null); String filePath = null; if (cur != null && cur.moveToNext()) { filePath = cur.getString(0); } if (filePath != null) { new MediaScannerNotifier(SmugDroid.ACTIVE_INSTANCE, filePath, null); } private class MediaScannerNotifier implements MediaScannerConnectionClient { private Context mContext; private MediaScannerConnection mConnection; private String mPath; private String mMimeType; public MediaScannerNotifier(Context context, String path, String mimeType) { mContext = context; mPath = path; mMimeType = mimeType; mConnection = new MediaScannerConnection(mContext, this); mConnection.connect(); } public void onMediaScannerConnected() { mConnection.scanFile(mPath, mMimeType); } public void onScanCompleted(String path, final Uri uri) { try { mMsgHandler.post(new Runnable() { public void run() { // Tell your app the pic has been taken and // has been saved OK. } }); } finally { mConnection.disconnect(); mContext = null; } } } [/code snippet] My question is: Will this work-around break if this bug in Gallery gets fixed (in the Cupcake release)? On Mar 2, 11:07 am, Marco Nelissen <marc...@android.com> wrote: > This is a bug in the Gallery, which is fixed in Cupcake. > Also note that with the code you posted, you will end up with a copy > of the image on the sd card, so you should either delete the original > once you're done, or you should not use insertImage(), but instead > insert an entry in to the database, or run the mediascanner so it will > pick up the file. > > > > On Mon, Mar 2, 2009 at 7:03 AM, david liu <wanqing.da...@gmail.com> wrote: > > Similar error is happened. Could anyone help? > > > On Tue, Feb 24, 2009 at 9:22 AM, Freddy <f...@charter.net> wrote: > > >> I'm running android sdk v1.1-r1 testing with a T-Mobile G1 device > >> HT841GZ04082. > > >> I have a jpg on the sdcard that I want to add to the photo viewer. I > >> do this quite simply with the test code > > >> Bitmap bm = BitmapFactory.decodeFile("/sdcard/test.jpg"); > >> String test = Images.Media.insertImage(getContentResolver(), bm, > >> "title", "desciption"); > > >> which appears to work fine. I receive a value for bm and test is > >> "content://media/external/images/media/163" or such. All great to > >> this point....yuppie! > > >> Now the problem; when I launch photo viewer from the home screen it > >> always crashes until I reset the phone. Here's the crash dump with an > >> uncaught exception. I assume this is a bug in the andoid photo > >> viewer. Can anyone verify this and/or let me know how else I can add > >> an existing jpg to the photo viewer without crashing the app? > > >> Thanks. > > >> 02-23 16:47:09.152: ERROR/AndroidRuntime(368): Uncaught handler: > >> thread main exiting due to uncaught exception > >> 02-23 16:47:09.162: ERROR/AndroidRuntime(368): > >> java.lang.RuntimeException: Unable to resume activity > >> {com.android.camera/com.android.camera.GalleryPicker}: > >> java.lang.NullPointerException > >> 02-23 16:47:09.162: ERROR/AndroidRuntime(368): at > >> android.app.ActivityThread.performResumeActivity(ActivityThread.java: > >> 2505) > >> 02-23 16:47:09.162: ERROR/AndroidRuntime(368): at > >> android.app.ActivityThread.handleResumeActivity(ActivityThread.java: > >> 2520) > >> 02-23 16:47:09.162: ERROR/AndroidRuntime(368): at > >> android.app.ActivityThread.handleLaunchActivity(ActivityThread.java: > >> 2160) > >> 02-23 16:47:09.162: ERROR/AndroidRuntime(368): at > >> android.app.ActivityThread.access$1800(ActivityThread.java:112) > >> 02-23 16:47:09.162: ERROR/AndroidRuntime(368): at > >> android.app.ActivityThread$H.handleMessage(ActivityThread.java:1581) > >> 02-23 16:47:09.162: ERROR/AndroidRuntime(368): at > >> android.os.Handler.dispatchMessage(Handler.java:88) > >> 02-23 16:47:09.162: ERROR/AndroidRuntime(368): at > >> android.os.Looper.loop(Looper.java:123) > >> 02-23 16:47:09.162: ERROR/AndroidRuntime(368): at > >> android.app.ActivityThread.main(ActivityThread.java:3739) > >> 02-23 16:47:09.162: ERROR/AndroidRuntime(368): at > >> java.lang.reflect.Method.invokeNative(Native Method) > >> 02-23 16:47:09.162: ERROR/AndroidRuntime(368): at > >> java.lang.reflect.Method.invoke(Method.java:515) > >> 02-23 16:47:09.162: ERROR/AndroidRuntime(368): at > >> com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run > >> (ZygoteInit.java:739) > >> 02-23 16:47:09.162: ERROR/AndroidRuntime(368): at > >> com.android.internal.os.ZygoteInit.main(ZygoteInit.java:497) > >> 02-23 16:47:09.162: ERROR/AndroidRuntime(368): at > >> dalvik.system.NativeStart.main(Native Method) > >> 02-23 16:47:09.162: ERROR/AndroidRuntime(368): Caused by: > >> java.lang.NullPointerException > >> 02-23 16:47:09.162: ERROR/AndroidRuntime(368): at > >> com.android.camera.GalleryPicker$GalleryPickerAdapter.init > >> (GalleryPicker.java:251) > >> 02-23 16:47:09.162: ERROR/AndroidRuntime(368): at > >> com.android.camera.GalleryPicker.rebake(GalleryPicker.java:96) > >> 02-23 16:47:09.162: ERROR/AndroidRuntime(368): at > >> com.android.camera.GalleryPicker.onResume(GalleryPicker.java:435) > >> 02-23 16:47:09.162: ERROR/AndroidRuntime(368): at > >> android.app.Instrumentation.callActivityOnResume(Instrumentation.java: > >> 1224) > >> 02-23 16:47:09.162: ERROR/AndroidRuntime(368): at > >> android.app.Activity.performResume(Activity.java:3359) > >> 02-23 16:47:09.162: ERROR/AndroidRuntime(368): at > >> android.app.ActivityThread.performResumeActivity(ActivityThread.java: > >> 2492) > >> 02-23 16:47:09.162: ERROR/AndroidRuntime(368): ... 12 more- Hide > >> quoted text - > > - Show quoted text - --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers-unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en -~----------~----~----~----~------~----~------~--~---