Fail to connect to camera service的几种原因和解决方法

2014年10月27日 Android 5条评论 阅读100385次

Fail to connect to camera service的几种原因和解决方法

     Will.Zhang        


10-21 09:42:08.979: I/SurfaceTextureClient(27049): [STC::queueBuffer] (this:0x78327870) fps:8.37, dur:1075.18, max:127.87, min:110.41
10-21 09:42:09.947: A/libc(27049): Fatal signal 11 (SIGSEGV) at 0x21547b1c (code=1), thread 27150 (Thread-2261)
10-21 09:42:09.948: A/libc(27049): Send stop signal to pid:27049 in debugger_signal_handler
10-21 09:42:10.527: W/dalvikvm(27262): threadid=1: thread exiting with uncaught exception (group=0x41a0faf8)
10-21 09:42:10.527: W/dalvikvm(27262): threadid=1: uncaught exception occurred
10-21 09:42:10.527: W/System.err(27262): java.lang.RuntimeException: Unable to start activity ComponentInfo{net.jileniao.android.exampleapp/net.jileniao.android.exampleapp.activity.MyCameraActivity}: java.lang.RuntimeException: Fail to connect to camera service
10-21 09:42:10.528: W/System.err(27262): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2358)
10-21 09:42:10.528: W/System.err(27262): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2410)
10-21 09:42:10.528: W/System.err(27262): at android.app.ActivityThread.access$600(ActivityThread.java:169)
10-21 09:42:10.528: W/System.err(27262): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1380)
10-21 09:42:10.528: W/System.err(27262): at android.os.Handler.dispatchMessage(Handler.java:107)
10-21 09:42:10.528: W/System.err(27262): at android.os.Looper.loop(Looper.java:194)
10-21 09:42:10.528: W/System.err(27262): at android.app.ActivityThread.main(ActivityThread.java:5463)
10-21 09:42:10.528: W/System.err(27262): at java.lang.reflect.Method.invokeNative(Native Method)
10-21 09:42:10.528: W/System.err(27262): at java.lang.reflect.Method.invoke(Method.java:525)
10-21 09:42:10.529: W/System.err(27262): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:854)
10-21 09:42:10.529: W/System.err(27262): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:621)
10-21 09:42:10.529: W/System.err(27262): at dalvik.system.NativeStart.main(Native Method)
10-21 09:42:10.529: W/System.err(27262): Caused by: java.lang.RuntimeException: Fail to connect to camera service
10-21 09:42:10.534: W/System.err(27262): at android.hardware.Camera.native_setup(Native Method)
10-21 09:42:10.534: W/System.err(27262): at android.hardware.Camera.<init>(Camera.java:463)
10-21 09:42:10.534: W/System.err(27262): at android.hardware.Camera.open(Camera.java:412)
10-21 09:42:10.534: W/System.err(27262): at net.jileniao.android.exampleapp.activity.MyCameraActivity.SecondaryCameraSizeSelect(MyCameraActivity.java:517)
10-21 09:42:10.535: W/System.err(27262): at net.jileniao.android.exampleapp.activity.MyCameraActivity.onCreate(MyCameraActivity.java:220)
10-21 09:42:10.535: W/System.err(27262): at android.app.Activity.performCreate(Activity.java:5122)
10-21 09:42:10.535: W/System.err(27262): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1151)
10-21 09:42:10.535: W/System.err(27262): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2322)
10-21 09:42:10.535: W/System.err(27262): ... 11 more
10-21 09:42:10.535: W/dalvikvm(27262): threadid=1: calling UncaughtExceptionHandler


在应用开发中涉及到camera相关的操作经常会出现Fail to connect to camera service的问题,相应的也就会出现上面类似的错误异常日志。
下面就出现这个错误的场景和原因简单做下分析。

1.手机上有安装安全过滤软件。因为camera属于较为敏感的权限,所以,有些手机安全管家会自动拒绝camera的打开操作。
  针对这种错误,可以在手机安全管家软件中,降低一下camera的安全级别,或把自己的APP添加到白名单中。
  
2.AndroidManifest.xml中没有添加camera的权限申请,对策则是添加<uses-permission android:name="android.permission.CAMERA"/>权限申请。

3.之前对camera打开后,并没有释放掉。
  解决对策就是调用下面的处理
  camera.stopPreview();
  camera.release();
  camera = null;

4.内存占用过多,可能导致了自己应用可分配的内存不足了。
  这个场景的错误差不多是在自己的应用中打开摄像头,对摄像头取得的每一帧数据都进行额外的处理,随着处理次数的增加,如果有没被及时销毁的对象存在,则就极有可能会导致本文开头出现的异常了。
  针对此种问题,解决的方法就是仔细检查下临时创建的对象是否都已经释放掉。

本文终,有问题或不同意见欢迎留言提出,谢谢!

分享本文至:

WRITTEN BY

avatar
本文标签:androidcamera
看了本文是不是觉得很赞,那就赶紧点击下面按钮分享给身边的朋友吧!

5 条评论

  1. avatar 大布丁

    厉害了!!

  2. avatar 小布丁

    我照着上面解决问题的检查了下,可是还是会java.lang.RuntimeException: Fail to connect to camera service

    • @小布丁:能说下 具体出错场景或上下文吗?

      • @极乐鸟:错误:E/AndroidRuntime: FATAL EXCEPTION: main
                          Process: wuyi.com.shouji, PID: 3221
                          java.lang.RuntimeException: Unable to start activity ComponentInfo{wuyi.com.shouji/wuyi.com.shouji.test.tv_4Activity}: java.lang.RuntimeException: Fail to connect to camera service
                              at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2416)
                              at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476)
                              at android.app.ActivityThread.-wrap11(ActivityThread.java)
                              at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344)
                              at android.os.Handler.dispatchMessage(Handler.java:102)
                              at android.os.Looper.loop(Looper.java:148)
                              at android.app.ActivityThread.main(ActivityThread.java:5417)
                              at java.lang.reflect.Method.invoke(Native Method)
                              at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
                              at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
                           Caused by: java.lang.RuntimeException: Fail to connect to camera service
                              at android.hardware.Camera.<init>(Camera.java:495)
                              at android.hardware.Camera.open(Camera.java:356)
                              at wuyi.com.shouji.adapter.PhoneManager.getMaxPhotoSize(PhoneManager.java:323)
                              at wuyi.com.shouji.test.tv_4Activity.init(tv_4Activity.java:95)
                              at wuyi.com.shouji.test.tv_4Activity.onCreate(tv_4Activity.java:54)
                              at android.app.Activity.performCreate(Activity.java:6237)
                              at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1107)
                              at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2369)
                              at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476) 
                              at android.app.ActivityThread.-wrap11(ActivityThread.java) 
                              at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344) 
                              at android.os.Handler.dispatchMessage(Handler.java:102) 
                              at android.os.Looper.loop(Looper.java:148) 
                              at android.app.ActivityThread.main(ActivityThread.java:5417) 
                              at java.lang.reflect.Method.invoke(Native Method) 
                              at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726) 
                              at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616) 

  3. avatar 1ee

    对我有用

欢迎留言




用户登录

sitemap