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.
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;
}
On May 7, 12:38 am, Mark Murphy <[email protected]> wrote:
> Anna PS wrote:
> > I need to start the Camera activity from within my application, take a
> > picture, and return the photo URI to another activity.
>
> > Surely this should be straightforward? But the Camera API sample code
> > doesn't show how to get the URI. I can't find the answer on this
> > forum, either.
>
> Since the Camera activity could be used to take one or 100 pictures, I
> would be surprised if it returned a result.
>
> The Camera *class* ("Camera API") gives you a JPEG file as a byte array.
> It is up to you to store that someplace (e.g., SD card, Web service).
>
> --
> 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 [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
-~----------~----~----~----~------~----~------~--~---