Android的错误:无法连接到卡马拉 [英] Android Error : Can't Connect to the Camara

查看:234
本文介绍了Android的错误:无法连接到卡马拉的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想打开默认的移动相机上的一个按钮点击。我曾尝试以下code:

I want to open the default mobile camera on a button click. I have tried the following code:

  Camera=(Button)findViewById(R.id.CameraID);
  Camera.setOnClickListener(new OnClickListener() {

    @Override
    public void onClick(View v) {
        // TODO Auto-generated method stub
        Intent Intent3=new   Intent(MediaStore.INTENT_ACTION_STILL_IMAGE_CAMERA);
        startActivity(Intent3); 
    }
});

我还增加了以下权限的Andr​​oid清单文件:

I also added the following permission in the Android Manifest file:

 <uses-permission android:name="android.permission.CAMERA" />
 <uses-feature android:name="android.hardware.camera" />

我还看到一个错误,当我点击拍照键。相机加载但之后,我得到一个消息的无法连接到丹在屏幕上。

推荐答案

据我了解,你实际上必须用的 ACTION_IM​​AGE_CAPTURE 行动,而不是<一href=\"http://developer.android.com/reference/android/provider/MediaStore.html#INTENT_ACTION_STILL_IMAGE_CAMERA\"相对=nofollow> INTENT_ACTION_STILL_IMAGE_CAMERA )。然后,在的onActivityResult 你必须从意向获取数据:在那里你会发现参考图像。
欲了解更多信息请参阅接收相机意图的结果


因此,使用

As far as I understand it, you actually would have to launch your intent with the ACTION_IMAGE_CAPTURE action (instead of INTENT_ACTION_STILL_IMAGE_CAMERA). Then, in onActivityResult you have to get the data from the Intent: there you will find the reference to the image. For more info see at Receiving camera intent result
So use

MediaStore.ACTION_IMAGE_CAPTURE

而不是

MediaStore.INTENT_ACTION_STILL_IMAGE_CAMERA

修改

您可以使用此方法来检查,如果相机是另一个应用程序或打开不但要这东西记住,此方法首先获取摄像机

You can use this method to check if camera is open by another app or not but keep this thing in mind that this method first acquire the camera

public boolean isCameraUsebyApp() {
    Camera camera = null;
    try {
        camera = Camera.open();
    } catch (RuntimeException e) {
        return true;
    } finally {
        if (camera != null) camera.release();
    }
    return false;
}

如果其获取成功那么它意味着没有其他应用程序正在使用这台相机,不要忘记再次释放它,否则你将无法再获取它。

If its acquire successfully then its mean that no other application is using this camera and don't forgot to release it again otherwise you will not able to acquire it again.

其throws 的RuntimeException 这意味着摄像机正被另一个进程或设备的策略管理器使用已禁用摄像头。

Its throws RuntimeException it means that camera is in use by another process or device policy manager has disabled the camera.

这篇关于Android的错误:无法连接到卡马拉的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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