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

2014年10月27日 Android 16条评论 阅读158133次

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

16 条评论

  1. <a href="http://www.publiswiss.net/nike-air-jordan-4-iv-oreos-kvinners-sko-svart-gr%C3%A5-schuheb">nike air jordan 4 iv oreos kvinners sko svart gr氓</a> <a href="http://www.puffyp.net/nike-flyknit-lunar-2-lux-marron-butyc">nike flyknit lunar 2 lux marron</a> <a href="http://www.radiosbestfriend.net/nike-lebron-12-low-nero-gituttio-obuvf">nike lebron 12 low nero gituttio</a> <a href="http://www.relaxmassagestudio.net/nike-kyrie-1-schwarz-edition-obuvf">nike kyrie 1 schwarz edition</a> <a href="http://www.risaralda.net/adidas-prougeator-fs-ultimate-kurpese">adidas prougeator fs ultimate</a> <a href="http://www.santfeliucentre.net/nike-foamposite-fruity-pebbles-svart-pants-schuhee">nike foamposite fruity pebbles svart pants</a>
    bluemoonocc http://www.bluemoonocc.net/

  2. <a href="http://www.rokettubemi.com/trevor-ariza-jersey-nflh">trevor ariza jersey</a> <a href="http://www.cumjacket.com/nike-free-flyknit-5.0-htm-sp-blanco-light-charcoal-shoese">nike free flyknit 5.0 htm sp blanco light charcoal</a> <a href="http://www.hzrdcraft.com/ralph-lauren-leather-weekend-bag-poloh">ralph lauren leather weekend bag</a> <a href="http://www.clubrockorg.com/nike-kobe-ix-high-blu-foota">nike kobe ix high blu</a> <a href="http://www.giaiphapdautu.com/air-max-thea-atomic-rosa-otto-runninga">air max thea atomic rosa otto</a> <a href="http://www.spreymax.com/air-jordan-future-gul-gr%C3%B8nn-scarpef">air jordan future gul gr酶nn</a>
    ftorrentz http://www.ftorrentz.com/

  3. <a href="http://www.lumalender.com/elite-matt-prater-youth-jersey-denver-broncos-5-alternate-navy-blue-nflb">elite matt prater youth jersey denver broncos 5 alternate navy blue</a> <a href="http://www.bkgutters.com/bon-march%C3%A9-air-jordan-melo-femmes-jaune-sportsb">bon march茅 air jordan melo femmes jaune</a> <a href="http://www.getawayoffer.com/kobe-10-christmas-grinch-trainersf">kobe 10 christmas grinch</a> <a href="http://www.busrockerz.com/new-arrival-adidas-shoes-skor">new arrival adidas shoes</a> <a href="http://www.prismbuffalo.com/tom-brady-embroidered-jersey-nflr">tom brady embroidered jersey</a> <a href="http://www.damimiyy.com/oakland-raiders-15-michael-crabtree-olive-2017-salute-to-service-limited-jersey-nflv">oakland raiders 15 michael crabtree olive 2017 salute to service limited jersey</a>
    ammampart http://www.ammampart.com/

  4. avatar tvpropria

    <a href="http://www.maninatravel.com/nike-roshe-run-speckle-r%C3%B8d-gull-foota">nike roshe run speckle r酶d gull</a> <a href="http://www.aroundbalkans.com/air-jordan-5-blau-runningd">air jordan 5 blau</a> <a href="http://www.taxrightllc.com/nfl-pittsburgh-steelers-color-rush-limited-antonio-brown-mens-football-jersey-nflh">nfl pittsburgh steelers color rush limited antonio brown mens football jersey</a> <a href="http://www.dlxcommerce.com/hommes-nike-air-max-98-naranja-zapatosh">hommes nike air max 98 naranja</a> <a href="http://www.wheelsongs.com/air-max-tailwind-8-for-vendita-craigslist-scarpea">air max tailwind 8 for vendita craigslist</a> <a href="http://www.asksohbetim.com/clemson-bucket-hat-hati">clemson bucket hat</a>
    tvpropria http://www.tvpropria.com/

  5. avatar tekmenu

    <a href="http://www.seesoshow.com/hombres-nike-free-run-3-blanco-zapatosh">hombres nike free run 3 blanco</a> <a href="http://www.crypolio.com/nike-air-max-90-mujer-wholeventa-marr%C3%B3n-blanco-azul-zapatosk">nike air max 90 mujer wholeventa marr贸n blanco azul</a> <a href="http://www.vtrvideo.com/north-face-polartec-denali-fleece-northfaceh">north face polartec denali fleece</a> <a href="http://www.asoseinhalb.com/adidas-pure-boost-2-schwarz-schuhek">adidas pure boost 2 schwarz</a> <a href="http://www.handydgh.com/gr%C3%B8n-converse-sko-skoi">gr酶n converse sko</a> <a href="http://www.blakefanz.com/converse-jaune-low-chaussuresh">converse jaune low</a>
    tekmenu http://www.tekmenu.com/

  6. avatar milajerdchat

    <a href="http://www.flushnhunt.com/nike-zoom-pegasus-34-dam%C3%A4nner-blau-grau-schuhei">nike zoom pegasus 34 dam盲nner blau grau</a> <a href="http://www.evelpa.com/hombres-nike-air-max-tailwind-8-blanco-verde-zapatosp">hombres nike air max tailwind 8 blanco verde</a> <a href="http://www.taaliminfos.com/under-armour-curry-2-appelsin-r%C3%B8d-skoi">under armour curry 2 appelsin r酶d</a> <a href="http://www.cacikvideo.com/nike-kobe-11-flyknit-gr%C3%A5-gull-obuvq">nike kobe 11 flyknit gr氓 gull</a> <a href="http://www.grossavind.com/womens-adidas-stan-smith-red-shoesh">womens adidas stan smith red</a> <a href="http://www.boltsfans.com/nike-kobe-xi-elite-rosso-horse-scarpei">nike kobe xi elite rosso horse</a>
    milajerdchat http://www.milajerdchat.com/

  7. avatar townyplay

    <a href="http://www.forttr.com/nike-roshe-run-men-leather-black-grass-green-shoesj">nike roshe run men leather black grass green</a> <a href="http://www.chopkinslaw.com/nike-zoom-lebron-xii-12-green-black-shoesl">nike zoom lebron xii 12 green black</a> <a href="http://www.plusbolivia.com/green-ralph-lauren-sweater-poloh">green ralph lauren sweater</a> <a href="http://www.ahlivv.com/nike-air-zoom-pegasus-33-kvinder-bl%C3%A5-orange-hvid-skok">nike air zoom pegasus 33 kvinder bl氓 orange hvid</a> <a href="http://www.bybrettbarner.com/nike-shox-wei%C3%9F-blau-schuheh">nike shox wei脽 blau</a> <a href="http://www.timowallets.com/adidas-boost-shoes-pink-shoesk">adidas boost shoes pink</a>
    townyplay http://www.townyplay.com/

  8. avatar dkdjabar

    <a href="http://www.cardiachits.com/prada-1810-bags-in-black-11-pradah">prada 1810 bags in black 11</a> <a href="http://www.zestchannel.com/demar-derozan-swingman-black-jersey-nfli">demar derozan swingman black jersey</a> <a href="http://www.eczacinim.com/air-jordan-retro-29-mintgr%C3%B8n-guld-skol">air jordan retro 29 mintgr酶n guld</a> <a href="http://www.chilangorails.com/ralph-lauren-hoodie-no-zip-poloh">ralph lauren hoodie no zip</a> <a href="http://www.mariusen.com/womens-asics-gel-kinsei-4-gold-purple-shoesi">womens asics gel kinsei 4 gold purple</a> <a href="http://www.brittonoilco.com/air-jordan-retro-5-womens-orange-red-shoesp">air jordan retro 5 womens orange red</a>
    dkdjabar http://www.dkdjabar.com/

  9. avatar midatlantech

    <a href="http://www.chipcolley.com/nfl-nike-pittsburgh-steelers-77-marcus-gilbert-black-name-number-logo-t-shirt-nfls">nfl nike pittsburgh steelers 77 marcus gilbert black name number logo t shirt</a> <a href="http://www.golfthebeach.com/nike-air-max-90-jcrd-jacquard-ivory-mettodasic-oro-mettodasic-plata-scarpeg">nike air max 90 jcrd jacquard ivory mettodasic oro mettodasic plata</a> <a href="http://www.krzysztofkrol.com/nike-dam%C3%A4nner-free-5.0-laufen-trainer-rosa-obuvc">nike dam盲nner free 5.0 laufen trainer rosa</a> <a href="http://www.ondecktrivia.com/lebron-12-scarpe-weight-scarpea">lebron 12 scarpe weight</a> <a href="http://www.gopinksoccer.com/bon-march%C3%A9-nike-air-griffey-max-360-schuheb">bon march茅 nike air griffey max 360</a> <a href="http://www.iamfitshop.com/nike-youth-jason-mccourty-limited-olive-jersey-new-england-patriots-nfl-30-2017-salute-to-service-nflr">nike youth jason mccourty limited olive jersey new england patriots nfl 30 2017 salute to service</a>
    [url=http://www.midatlantech.com/]midatlantech[/url]

  10. avatar pizzablitzmd

    <a href="http://www.gaialog.net/asics-gel-lyte-5-naranja-negro-obuvb">asics gel lyte 5 naranja negro</a> <a href="http://www.genopresse.net/nike-flyknit-racer-lyser%C3%B8d-bl%C3%A5-kurpesa">nike flyknit racer lyser酶d bl氓</a> <a href="http://www.gpsgolfcaddy.net/roshe-run-gr%C3%A5-butyc">roshe run gr氓</a> <a href="http://www.gregoryjewellers.net/nike-air-pegasus-32-herren-billig-butye">nike air pegasus 32 herren billig</a> <a href="http://www.hamiltonbookkeeping.net/grigio-and-hot-rosa-nike-free-runs-kurpesd">grigio and hot rosa nike free runs</a> <a href="http://www.handykontakte.net/asics-gel-noosa-tri-7-cammello-schuhea">asics gel noosa tri 7 cammello</a>
    pizzablitzmd http://www.pizzablitzmd.net/

  11. avatar Xinren

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

  12. avatar 大布丁

    厉害了!!

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

  14. avatar 1ee

    对我有用

欢迎留言




用户登录

sitemap