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

2014年10月27日 Android 19条评论 阅读152628次

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
看了本文是不是觉得很赞,那就赶紧点击下面按钮分享给身边的朋友吧!

19 条评论

  1. <a href="http://www.sophiecrooks.com/under-armour-clutchfit-drive-stephen-curry-gelb-blau-schuheh">under armour clutchfit drive stephen curry gelb blau</a> <a href="http://www.hkelitemodels.com/men-kd-vii-white-red-black-shoesk">men kd vii white red black</a> <a href="http://www.graciecomm.com/converse-alle-star-r%C3%B8d-kvinders-skoj">converse alle star r酶d kvinders</a>
    pariswebjob http://www.pariswebjob.com/

  2. <a href="http://www.priakurus.com/nikelab-air-force-1-low-p%C3%BArpura-stardust-citron-zapatosk">nikelab air force 1 low p煤rpura stardust citron</a> <a href="http://www.batatastudio.com/adidas-sl-predator-shoesj">adidas sl predator</a> <a href="http://www.kahawellness.com/los-angeles-chargers-new-era-2018-nfl-training-9twenty-cap-hath">los angeles chargers new era 2018 nfl training 9twenty cap</a> <a href="http://www.metabolifes.com/nike-kobe-11-negro-blanco-venta-online-zapatosl">nike kobe 11 negro blanco venta online</a> <a href="http://www.breconpharm.com/nike-grey-air-max-womens-shoesk">nike grey air max womens</a> <a href="http://www.bagintaiwan.com/gr%C3%B8nn-and-gul-converse-obuvi">gr酶nn and gul converse</a>
    lopifitfl http://www.lopifitfl.com/

  3. <a href="http://www.swnblog.com/billig-nike-hyperdunk-2015-dam%C3%A4nner-grau-skob">billig nike hyperdunk 2015 dam盲nner grau</a> <a href="http://www.weimpactmds.com/minnesota-vikings-new-era-nfl-on-field-59fifty-cap-purple-hatc">minnesota vikings new era nfl on field 59fifty cap purple</a> <a href="http://www.relsflorida.com/yeezy-boost-350-infant-pirate-black-man-runninge">yeezy boost 350 infant pirate black man</a> <a href="http://www.votuongluan.com/air-jordan-4-retro-hvid-metalleic-s%C3%B8lv-schuhea">air jordan 4 retro hvid metalleic s酶lv</a> <a href="http://www.hanayaflowers.com/nike-free-5.0-mujeres-amarillo-rosado-scarpec">nike free 5.0 mujeres amarillo rosado</a> <a href="http://www.jlchatlaw.com/nike-air-max-2019-green-uk-shoeso">nike air max 2019 green uk</a>
    oldoyopark http://www.oldoyopark.com/

  4. <a href="http://www.jobbstockholm.com/mennns-nike-free-run-3.0-v6-gull-gr%C3%B8nn-obuva">mennns nike free run 3.0 v6 gull gr酶nn</a> <a href="http://www.johnklymshyn.com/hombres-ralph-lauren-pony-shorts-p%C3%BArpura-rosado-polox">hombres ralph lauren pony shorts p煤rpura rosado</a> <a href="http://www.medicinennet.com/adidas-ultra-boost-zebra-for-vendita-va-schuhee">adidas ultra boost zebra for vendita va</a> <a href="http://www.nereephotos.com/herre-nike-flyknit-lunar-1-bl%C3%A5-lilla-scarped">herre nike flyknit lunar 1 bl氓 lilla</a> <a href="http://www.nutraxtractor.com/nfl-pittsburgh-steelers-black-custom-name-number-helmet-pullover-hoodie-nflx">nfl pittsburgh steelers black custom name number helmet pullover hoodie</a> <a href="http://www.resqglobal.com/green-bay-packers-damarious-randall-official-nike-white-game-women-s-road-nfl-jersey-nflz">green bay packers damarious randall official nike white game women s road nfl jersey</a>
    liaqui http://www.liaqui.com/

  5. <a href="http://www.eworklife.com/ua-micro-g-torch-blue-white-skoa">ua micro g torch blue white</a> <a href="http://www.fullcountkbo.com/nike-free-tr-versatility-sneakere">nike free tr versatility</a> <a href="http://www.shackofstones.com/hommes-nike-roshe-run-floral-or-violet-kurpesa">hommes nike roshe run floral or violet</a> <a href="http://www.tamworthbacon.com/nike-air-huarache-light-womens-silver-blue-sneakerb">nike air huarache light womens silver blue</a> <a href="http://www.dvmengineers.com/bon-march%C3%A9-air-jordan-after-game-femmes-gris-shoesg">bon march茅 air jordan after game femmes gris</a> <a href="http://www.questoffine.com/hurley-hat-aloha-hats">hurley hat aloha</a>
    ankaralokanta http://www.ankaralokanta.com/

  6. <a href="http://www.ambitionagent.com/nike-kyrie-2-noir-and-bleu-guide-obuvg">nike kyrie 2 noir and bleu guide</a> <a href="http://www.brensonford.com/air-jordan-12-ovo-wei%C3%9F-gold-scarped">air jordan 12 ovo wei脽 gold</a> <a href="http://www.dutting.com/air-jordan-melo-grigio-nero-butya">air jordan melo grigio nero</a> <a href="http://www.erickasouza.com/air-jordan-12-retro-lyser%C3%B8d-radio-chaussuresf">air jordan 12 retro lyser酶d radio</a> <a href="http://www.flyboardbc.com/nike-free-3.0-v4-gr%C3%A5-lyser%C3%B8d-butya">nike free 3.0 v4 gr氓 lyser酶d</a> <a href="http://www.mommypads.com/nike-free-5.0-mennns-light-gr%C3%A5-schuheg">nike free 5.0 mennns light gr氓</a>
    enescomert http://www.enescomert.com/

  7. avatar rx3wvk23

    <a href="http://www.ruyvu424.com/kvinners-asics-gel-kayano-20-hvit-gr%C3%B8nn-obuve">kvinners asics gel kayano 20 hvit gr酶nn</a> <a href="http://www.8q86xyek.com/jordan-5-noir-grape-style-code-kurpesd">jordan 5 noir grape style code</a> <a href="http://www.nvzpsk97.com/nike-lebron-11-sort-and-bl%C3%A5-schuhed">nike lebron 11 sort and bl氓</a> <a href="http://www.ddpu3p9v.com/nike-lunarglide-7-mujeres-corriendo-zapato-kurpesf">nike lunarglide 7 mujeres corriendo zapato</a> <a href="http://www.mqb193qn.com/air-max-95-blanco-and-oro-obuva">air max 95 blanco and oro</a> <a href="http://www.76yfbkug.com/nike-lebron-11-alle-r%C3%B8d-obuvf">nike lebron 11 alle r酶d</a>
    rx3wvk23 http://www.rx3wvk23.com/

  8. avatar doanlawoffice

    <a href="http://www.enjoysanta.com/air-jordan-phase-23-classic-verde-gituttio-scarpeg">air jordan phase 23 classic verde gituttio</a> <a href="http://www.primarknorway.com/nike-air-max-2017-mujeres-p%C3%BArpura-and-negro-kurpese">nike air max 2017 mujeres p煤rpura and negro</a> <a href="http://www.ruoiled.com/adidas-zx-700-wei%C3%9F-gr%C3%BCn-schuhef">adidas zx 700 wei脽 gr眉n</a> <a href="http://www.zrxocphotos.com/air-jordan-1-university-azul-jordans-schuheb">air jordan 1 university azul jordans</a> <a href="http://www.faithboxteens.com/air-jordan-super-fly-iv-jaune-chaussuresd">air jordan super fly iv jaune</a> <a href="http://www.juegosmemes.com/new-blance-500-kinder-wei%C3%9F-rosa-butyg">new blance 500 kinder wei脽 rosa</a>
    doanlawoffice http://www.doanlawoffice.com/

  9. avatar jazzoutlaw

    <a href="http://www.autopilotart.com/herre-nike-roshe-run-hyp-gr%C3%B8n-gul-schuhed">herre nike roshe run hyp gr酶n gul</a> <a href="http://www.iflextoday.com/hombres-asics-gel-noosa-tri-8-naranja-rojo-butye">hombres asics gel noosa tri 8 naranja rojo</a> <a href="http://www.iamsamart.com/air-jordan-9-low-rosa-obuvd">air jordan 9 low rosa</a> <a href="http://www.groupontatil.com/herre-mizuno-wave-creation-13-guld-obuvg">herre mizuno wave creation 13 guld</a> <a href="http://www.dblynx.com/nike-air-max-thea-ultra-flyknit-bl%C3%A5-schuhef">nike air max thea ultra flyknit bl氓</a> <a href="http://www.alpertsonline.com/adidas-forum-mid-for-salg-mn-obuve">adidas forum mid for salg mn</a>
    jazzoutlaw http://www.jazzoutlaw.com/

  10. avatar lindatompkin

    <a href="http://www.meghanfresta.com/which-hermes-scarf-to-buy-scarfr">which hermes scarf to buy</a> <a href="http://www.coldwaterapps.com/nike-free-7-dam%C3%A4nner-grau-shoesa">nike free 7 dam盲nner grau</a> <a href="http://www.drmilliecalko.com/billig-nike-free-og-kvinders-r%C3%B8d-trainersce">billig nike free og kvinders r酶d</a> <a href="http://www.ovisausa.com/nike-air-max-1-gs-midnight-navy-sportsg">nike air max 1 gs midnight navy</a> <a href="http://www.lumalenders.com/star-wars-death-star-hat-hatr">star wars death star hat</a> <a href="http://www.eysenreich.com/discount-ray-ban-erika-brown-violet-sunglassesd">discount ray ban erika brown violet</a>
    lindatompkin http://www.lindatompkin.com/

  11. avatar sethba

    <a href="http://www.askforpauline.com/kobe-elite-low-nikeid-sneakere">kobe elite low nikeid</a> <a href="http://www.autosasart.com/green-fendi-belt-beltr">green fendi belt</a> <a href="http://www.klarinetino.com/billig-nike-air-max-95-menns-s%C3%B8lv-footc">billig nike air max 95 menns s酶lv</a> <a href="http://www.witeducates.com/nike-air-huarache-all-black-flight-footf">nike air huarache all black flight</a> <a href="http://www.dineet.com/new-balance-ml574-red-skou">new balance ml574 red</a> <a href="http://www.segwaycr.com/canada-goose-girls-kensington-canadagooser">canada goose girls kensington</a>
    sethba http://www.sethba.com/

  12. avatar vbmconseil

    <a href="http://www.uilstrategie.com/bon-march%C3%A9-nike-kobe-9-mid-femmes-jaune-trainerse">bon march茅 nike kobe 9 mid femmes jaune</a> <a href="http://www.apocreative.com/black-blue-mens-adidas-samba-primeknit-shoes-shoesb">black blue mens adidas samba primeknit shoes</a> <a href="http://www.easytanklevel.com/ray-ban-cats-5000-pink-sunglassesr">ray ban cats 5000 pink</a> <a href="http://www.mesassy.com/nike-free-run-3-fluo-skof">nike free run 3 fluo</a> <a href="http://www.eventyrshop.com/nike-free-flyknit-sz-10-footc">nike free flyknit sz 10</a> <a href="http://www.foremostgold.com/adidas-tubular-x-all-white-skot">adidas tubular x all white</a>
    [url=http://www.vbmconseil.com/]vbmconseil[/url]

  13. avatar selvasurf

    <a href="http://www.sfhires.com/billig-asics-onitsuka-tiger-mexico-66-dam%C3%A4nner-orange-runningf">billig asics onitsuka tiger mexico 66 dam盲nner orange</a> <a href="http://www.gregertopsoil.com/nike-free-trainer-7.0-herren-rot-runningg">nike free trainer 7.0 herren rot</a> <a href="http://www.rumelisut.com/toronto-blue-jays-floral-hat-2016-hatb">toronto blue jays floral hat 2016</a> <a href="http://www.brendonrush.com/nike-free-run-femminile-bianca-runningb">nike free run femminile bianca</a> <a href="http://www.adgamorese.com/adidas-rio-2016-wrestling-shoes-skou">adidas rio 2016 wrestling shoes</a> <a href="http://www.hobihobinomi.com/new-balance-shoe-factory-skor">new balance shoe factory</a>
    selvasurf http://www.selvasurf.com/

  14. avatar Xinren

    我的是没有前置摄像头所以打开失败了

  15. avatar 大布丁

    厉害了!!

  16. 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) 

  17. avatar 1ee

    对我有用

欢迎留言




用户登录

sitemap