安卓的java郎的RuntimeException无法连接到摄像机服务 [英] android java lang runtimeexception fail to connect to camera service

查看:776
本文介绍了安卓的java郎的RuntimeException无法连接到摄像机服务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前工作的手电筒开/关。我收到此错误了java.lang.RuntimeException:无法连接到摄像机服务我不知道为什么这个错误发生。我提到的很多解决方案,但仍然没有解决我的问题。当手电筒打开,不会发生错误,但是当手电筒是关闭的,然后发生错误。

I am currently working on Flashlight On/OFF. I am getting this error java.lang.RuntimeException: Fail to connect to camera service I don't know why this error is occurring. I referred to many solutions but my problem was still not solved. When flashlight is on, the error does not occur but when the flashlight is off then the error occurs.

我的code 主要code

我的清单权限:

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

我该如何解决呢?请帮我。

How can I solve it? Please help me.

推荐答案

试试这个...

 static Camera camera = null;

在上面声明。

declare it on top.

 try{ 
   if(clickOn == true) {
   clickOn = false;
   camera = Camera.open();
   Parameters parameters = camera.getParameters();
   parameters.setFlashMode(Parameters.FLASH_MODE_TORCH);
   camera.setParameters(parameters);
   camera.startPreview();

   remoteViews.setViewVisibility(R.id.button1, View.GONE);
   remoteViews.setViewVisibility(R.id.button2, View.VISIBLE);
   localAppWidgetManager.updateAppWidget(componentName, remoteViews);
   } else {
   clickOn = true;
   camera.stopPreview();
   camera.release();
   camera = null;

   remoteViews.setViewVisibility(R.id.button1, View.VISIBLE);
   remoteViews.setViewVisibility(R.id.button2, View.GONE);
   localAppWidgetManager.updateAppWidget(componentName, remoteViews);
   }    
   }catch(Exception e) {
   Log.e("Error", ""+e);}

这篇关于安卓的java郎的RuntimeException无法连接到摄像机服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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