摄像头活动不会返回previous /来电者活动 [英] camera activity does not return to the previous/caller activity

查看:148
本文介绍了摄像头活动不会返回previous /来电者活动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

我想要做的是,点击OK接受拍摄的照片后,我要显示举杯保存的路径。

问题是,当我点击确定接受画面,正在显示什么,我不能从相机活动切换到所谓的相机活动的previous活动活动

请注意:我使用的模拟器并不是一个真正的设备

  OnClickListener btn_TakePictureListener =新OnClickListener(){    @覆盖
    公共无效的onClick(视图v){
        // TODO自动生成方法存根
        意向意图=新意图(MediaStore.ACTION_IM​​AGE_CAPTURE);
        串imgPath = retrievePath();
        intent.putExtra(MediaStore.EXTRA_OUTPUT,getImageUri(imgPath));
        startActivityForResult(意向,询价code);
    }
};
@覆盖
保护无效的onActivityResult(INT申请code,INT结果code,意图数据){
    super.onActivityResult(要求code,结果code,数据);    如果(要求code ==请求code和;&安培;结果code == RESULT_OK){
       字符串s = data.getData()的toString()。
       Toast.makeText(getBaseContext(),+ S,Toast.LENGTH_SHORT).show();
    }
}


解决方案

如果你是开放的传递给你的图像,然后作为采取的摄像头,你可以检索图片:

 意向意图=新意图(MediaStore.ACTION_IM​​AGE_CAPTURE);
    intent.putExtra(MediaStore.EXTRA_OUTPUT,Uri.fromFile(新文件(
    Environment.getExternalStorageDirectory(),temp.jpg)));
    startActivityForResult(意向,1);
    @覆盖
    保护无效的onActivityResult(INT申请code,INT结果code,意图数据){
        如果(结果code == NONE)
            返回;        如果(要求code == 1){
            //设置文件保存目录路径
            文件图片=新的文件(Environment.getExternalStorageDirectory()
                    +/temp.jpg);
            乌里imageuri = Uri.fromFile(图片);
            //设置ImageView的位置
        }
}

编辑:

有关获取数据的URI的onActivityResult开始CAMRA Activiyt为:

 意向意图=新意图(Intent.ACTION_PICK,NULL);
 intent.setDataAndType(
 MediaStore.Images.Media.EXTERNAL_CONTENT_URI,IMAGE_UNSPECIFIED);
 startActivityForResult(意向,2);
     @覆盖
保护无效的onActivityResult(INT申请code,INT结果code,意图数据){
    如果(结果code == NONE)
        返回;
    如果(要求code == 1){
        乌里uriimg = data.getData();
        Toast.makeText(getBaseContext(),+ uriimg.toString(),Toast.LENGTH_SHORT).show();
        }
    }

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

解决方案

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

这篇关于摄像头活动不会返回previous /来电者活动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆