I'm calling the default camera from my activity and then handling the onActivityResult. My code seems to work fine on the LG Ally which doesn't have a confirmation when a picture is taken. However, when I run the same app on the Nexus S, it prompts me with an "Ok", "Retake", or "Cancel" before returning to my activity. While "Cancel" works, returning to my activity without saving the picture, "Ok" doesn't seem to have any effect, not even returning to my activity.
My code below:
private void captureImage() {
String state = Environment.getExternalStorageState();
if (Environment.MEDIA_MOUNTED.equals(state)) {
File path = new File(Environment.getExternalStorageDirectory().getPath() + "/Images/" + (new UserContextAdapter(this)).getUser() + "/");
path.mkdirs();
File file = new File(path, "Image_Story_" + mRowId.toString() + ".jpg");
newImageUri = Uri.fromFile(file);
Intent intent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
intent.putExtra(MediaStore.EXTRA_OUTPUT, newImageUri);
startActivityForResult(intent, CAPTURE_IMAGE);
}
}
@Override
public void onActivityResult(int requestCode, int resultCode, Intent intent) {
switch (requestCode) {
case CAPTURE_IMAGE:
switch (resultCode ) {
case 0:
Log.i("CAPTURE", "Cancelled by User");
break;
case -1:
mImageUri = newImageUri;
setImageFromUri();
}
}
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…