camera activity does not return to the previous/caller activity

不打扰是莪最后的温柔 提交于 2019-12-06 11:52:39

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