当startActivityForResult称为从相机返回() [英] Return from Camera when called with startActivityForResult()

查看:117
本文介绍了当startActivityForResult称为从相机返回()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的是相机通过创建一个意图:

I am using the camera by creating an intent:

Intent cameraI = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);

,然后启动它:

startActivityForResult(cameraI, request);

,其中请求是predefined整型常量。

where request is a predefined constant integer.

然后我有的onActivityResult():

I then have the onActivityResult():

public void onActivityResult(int req, int res, Intent data) throws NullPointerException
{
    try{

    super.onActivityResult(req, res, data);
    if(req == request)
    {
        Bitmap picture = (Bitmap) data.getExtras().get("data");
        ImageView image = (ImageView) findViewById(R.id.imageView1);
        image.setImageBitmap(picture);
    }//if
    else
    {
        Toast.makeText(getApplicationContext(), "No picture taken", 4);
    }//else
    }catch (NullPointerException e){
        String error = "null pointer exception";
        Toast.makeText(getApplicationContext(), error, 4);
    }
}//onActivityResult

我的predicament的是,我没有这个计算机上的摄像头。我得到Eclipse的默认棋盘动人广场动画。这实际上发挥作用?我一直点击拍照按钮,但什么也没有发生。我希望发生是采取单一的图片,然后将其返回到调用我的活动。是默认操作或我指定我希望它拍摄一张照片后回去呢?

My predicament is that I do not have a camera on this computer. I get eclipse's default checkerboard and moving square animation. Does this actually function? I have been clicking the "take picture" button but nothing is happening. What I want to happen is to take a single picture, and then return it to the activity that called i. Is that the default action or do I have to specify that I want it to return after taking one picture?

感谢您事先的任何帮助。

Thanks in advance for any help.

推荐答案

在讨论的code结束了工作。在一个装置上的测试中,根据需要被返回的图片。 Eclipse的模拟摄像头根本没有工作。如果我记错,您可以启用一个摄像头,但是这完全是一个不同的讨论。

The code in question ended up working. Upon testing on a device, the picture was returned as desired. Eclipse's emulated camera simply did not work. If i recall correctly you can enable a camera, but that is a different discussion entirely.

这篇关于当startActivityForResult称为从相机返回()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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