我只是遇到一个小问题。我成功打开相机,按下按钮捕捉图片后,会出现以下三个按钮:OK
,RETAKE
和CANCEL
。通常,当按下OK按钮时,摄像机活动应该正常返回到父活动并执行onActivityResult功能包含的内容。但在我的情况下,当按下OK时,相机活动不会返回到父活动。有没有解决这个问题的想法?
请在下面找到代码:
OnClickListener btn_TakePictureListener = new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
File imgPath = retrievePath();
intent.putExtra(MediaStore.EXTRA_OUTPUT, getImageUri(imgPath));
startActivityForResult(intent, RequestCode);
}
};
//@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
//super.onActivityResult(requestCode, resultCode, data);
if (RequestCode == requestCode && resultCode == RESULT_OK) {
String s = data.getDataString();
Toast.makeText(getBaseContext(), ""+s, Toast.LENGTH_SHORT).show();
Toast.makeText(getBaseContext(), "picture is taken", Toast.LENGTH_SHORT).show();
}
}
private String retrieveName() {
int []x = imgOpHlpr.getIDs();
String s = imgOpHlpr.getImg_Name(x.length);
return s;
}
private File retrievePath() {
int []x = imgOpHlpr.getIDs();
String s = Environment.getExternalStorageDirectory().getAbsolutePath();
s += "/myFolder/"+imgOpHlpr.getImg_Path(x.length);
File file = new File(s);
return file;
}
private Uri getImageUri(File path) {
Uri imgFileUri = Uri.fromFile(path);
return imgFileUri;
}
答案 0 :(得分:0)
我认为你应该实现这样的......
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
try{
if (requestCode == IMAGE_CAPTURE) {
if (resultCode == RESULT_OK) {
Intent intent = new Intent(CameraCapture.this, Home.class);
intent.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
finish();
startActivity(intent);
}
}
答案 1 :(得分:0)
您忘记创建编写图像的目录。 在创建文件对象之前添加此行。
File path = new File(Environment.getExternalStorageDirectory().getPath() + "/myFolder/").
path.mkdirs();