相机活动不会返回到它的父活动

时间:2012-06-05 13:11:54

标签: android android-intent android-camera

我正在尝试打开Android摄像头,当我按下OK时,摄像头活动应该返回到父活动“我开始摄像头活动的那个”

但现在发生的是,当我按OK时,相机活动仍然在屏幕上,并且不会返回到父活动。

    private String retrievePath() {
    int []x = imgOpHlpr.getIDs();
    String s = imgOpHlpr.getImg_Path(x.length);
    return s;       
}

代码

private static final int RequestCode = 0;
OnClickListener btn_TakePictureListener = new OnClickListener() {

    @Override
    public void onClick(View v) {
        // TODO Auto-generated method stub
        Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
        String 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.getData().toString();
       //Toast.makeText(getBaseContext(), ""+s, Toast.LENGTH_SHORT).show();
        Toast.makeText(getBaseContext(), "picture is taken", Toast.LENGTH_SHORT).show();
    }           
}

1 个答案:

答案 0 :(得分:2)

模拟器不提供相机支持。请参阅http://code.google.com/p/android/issues/detail?id=14545。请检查设备。

检查

if (resultCode == RESULT_OK) {
            if (data.getExtras().get("data") != null) {
                Bitmap photo = Bitmap.createScaledBitmap((Bitmap) data.getExtras().get("data"), 90, 90, false);
               if(photo != null){
                   Log.d("Photo","photo not null");
}