Anna PS wrote: > Thanks Mark. I've tried to intercept the Camera class's onKeyDown > event to save a picture and take the URI back to my home activity - > code below.
There is no onKeyDown() in the Camera class. http://developer.android.com/reference/android/hardware/Camera.html > Unfortunately, this is crashing with > "Java.Lang.UnsupportedOperationException: Unknown URI: > content://media/external/images/media". > > Can you advise? > > Anna > > public boolean onKeyDown(int keyCode, KeyEvent event) { > ImageCaptureCallback iccb = null; > Uri uri = null; > if (keyCode == KeyEvent.KEYCODE_DPAD_CENTER) { > Log.e(LOG_TAG, "KeyEvent.KEYCODE_DPAD_CENTER pressed"); > try { > String filename = timeStampFormat.format(new > Date()); > ContentValues values = new ContentValues(); > values.put(Media.TITLE, filename); > values.put(Media.DESCRIPTION, "Image capture by > camera"); > uri = > getContentResolver().insert(Media.EXTERNAL_CONTENT_URI, > values); > iccb = new > ImageCaptureCallback(getContentResolver() > .openOutputStream(uri)); > } catch (Exception ex) { > ex.printStackTrace(); > Log.e(getClass().getSimpleName(), > ex.getMessage(), ex); > } > } > if (keyCode == KeyEvent.KEYCODE_BACK) { > return super.onKeyDown(keyCode, event); > } > > if (keyCode == KeyEvent.KEYCODE_DPAD_CENTER) { > camera.takePicture(mShutterCallback, > mPictureCallbackRaw, iccb); > Log.d(LOG_TAG, > "Taken picture from > KeyEvent.KEYCODE_DPAD_CENTER, uri = " > + uri.toString()); > Intent i = new Intent(CameraActivity.this, Home.class); > i.setData(uri); > startActivity(i); > return true; > } > return false; > } I don't know how this code is being executed. I don't know what ImageCaptureCallback is. And I'm still not 100% sure why you're wanting a URI out of the deal. For some sample Camera-using code, you can grab the source code to my Advanced Android book: http://commonsware.com/AdvAndroid/ I can tell you that your code above has two keyCode == KeyEvent.KEYCODE_DPAD_CENTER items, which seems a bit odd given the structure of the method. If I were in your shoes, and going only by the limited use case you documented. I would: -- Use the Camera API to get the byte array -- Write the byte array to a JPEG file on the SD card -- Use that file as the basis for your thumbnail -- Use that file as the attachment in your email -- Let the Media content provider deal with indexing your image on its own time, or delete the image once it's emailed if you no longer need it It may be you have other criteria that cannot be met by the above procedure, in which case I apologize. -- Mark Murphy (a Commons Guy) http://commonsware.com | http://twitter.com/commonsguy _The Busy Coder's Guide to Android Development_ Version 2.0 Available! --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---