学习所捕获的图像中的onActivityResult方法的路径 [英] Learning the path of the captured image in onActivityResult method

查看:118
本文介绍了学习所捕获的图像中的onActivityResult方法的路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

@Override
protected void onCreate(Bundle savedInstanceState) {      
    super.onCreate(savedInstanceState);
    setContentView(R.layout.picture_choice_activity);

    Button takePictureButton = (Button)findViewById(R.id.takePictureButton);
    takePictureButton.setOnClickListener(new OnClickListener() {
        public void onClick(View v){
            Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
            startActivityForResult(intent, IMAGE_CAPTURE);
        }
    });
}

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    if(requestCode == IMAGE_CAPTURE){
        if(resultCode == Activity.RESULT_OK){
            // I should get the path here
        }else if(resultCode == Activity.RESULT_CANCELED){

        }
    }
}

在上面的code,我试图让所拍摄图像的路径。我不应该使用EXTRA_OUTPUT指定自定义路径保存图像。我该怎么做?

In the above code I am trying to get the path of the captured image. I should not use EXTRA_OUTPUT to specify a custom path to save the image. How can I do that?

推荐答案

请检查一下,的 http://developer.android.com/guide/topics/media/camera.html#intents

MediaStore.EXTRA_OUTPUT :此设置需要一个开放的对象,指定的路径和您希望保存图片的文件名。此设置是可选的,但强烈建议。如果不指定此值,相机应用程序保存在默认名称的默认位置所要求的图片,在返回的意图的Intent.getData()字段中指定。

MediaStore.EXTRA_OUTPUT : This setting requires a Uri object specifying a path and file name where you'd like to save the picture. This setting is optional but strongly recommended. If you do not specify this value, the camera application saves the requested picture in the default location with a default name, specified in the returned intent's Intent.getData() field.

所以,检查的onActivityResult的意图数据()

so, check the Intent data in onActivityResult()

这篇关于学习所捕获的图像中的onActivityResult方法的路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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