相机活动不会返回到先前/呼叫者活动(camera activity does not return

2019-09-17 17:34发布

我读了来自用户的文本输入,此输入我使用它作为一个画面我对相机拍摄的名称。

我保存这个名称和图像名称的路径到SQLite数据库。

我想要做的是,点击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);
        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();
    }           
}

Answer 1:

如果传递的URI您的图像,然后作为采取的摄像头,你可以检索图片:

 Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);  
    intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(new File(  
    Environment.getExternalStorageDirectory(), "temp.jpg")));  
    startActivityForResult(intent, 1); 
    @Override  
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {  
        if (resultCode == NONE)  
            return;  

        if (requestCode == 1) {  
            // Set the file save path with directory  
            File picture = new File(Environment.getExternalStorageDirectory()  
                    + "/temp.jpg");  
            Uri imageuri= Uri.fromFile(picture);        
            //set to imageview here 
        } 
}   

编辑:

对于获取数据的URI onActivityResult开始CAMRA Activiyt为:

 Intent intent = new Intent(Intent.ACTION_PICK, null);  
 intent.setDataAndType(  
 MediaStore.Images.Media.EXTERNAL_CONTENT_URI,IMAGE_UNSPECIFIED);  
 startActivityForResult(intent, 2);     
     @Override  
protected void onActivityResult(int requestCode, int resultCode, Intent data) {  
    if (resultCode == NONE)  
        return;  
    if (requestCode == 1) { 
        Uri uriimg = data.getData();
        Toast.makeText(getBaseContext(), ""+uriimg.toString(), Toast.LENGTH_SHORT).show();
        }
    }


文章来源: camera activity does not return to the previous/caller activity