camera activity does not return to the previous/caller activity

江枫思渺然 提交于 2019-12-10 10:36:17

问题


I read an text input from the user, this input i use it as a name of a picture i'm taking by the camera.

i store this name and the path of the image name into Sqlite Database.

what I'm trying to do is, after clicking OK to accept the taken picture, i want the saved path to be displayed in a toast.

the problem is, when I click OK to accept the picture, nothing is being displayed and i cant switch from the camera activity to the activity that called the camera activity"the previous activity"

Note: I'm using the emulator not a real device.

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();
    }           
}

回答1:


if you are passing Uri for you image then you can retrieve image as taken by camera:

 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 
        } 
}   

EDIT:

For Getting data uri in onActivityResult start Camra Activiyt as:

 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();
        }
    }


来源:https://stackoverflow.com/questions/10871315/camera-activity-does-not-return-to-the-previous-caller-activity

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!