构建AOA应用程序,我的Android设备与外部附件通信,在这种情况下是arduino.
当我连接附件时,我的Android应用程序正确启动,因为我的mainActivity的intent-filter中有USB_ATTACHED操作.
但是,我的Android应用程序很可能在与USB配件断开连接时崩溃.
我的shell在断开连接时立即从TCPIP切换到USB模式但重新连接我得到完整的堆栈跟踪
任何Android专家都可以根据以下logcat输出建议我如何进一步调试吗?
E/run ( 5092): java.io.IOException: read Failed: EIO (I/O error)
D/PicasaSyncManager( 4877): battery info: false
D/UsbDeviceManager( 781): exited USB accessory mode
E/UsbDebuggingManager( 781): got -1 reading
E/UsbDebuggingManager( 781): Communication error:
E/UsbDebuggingManager( 781): java.io.IOException: No such file or directory
E/UsbDebuggingManager( 781): at android.net.LocalSocketImpl.connectLocal(Native Method)
E/UsbDebuggingManager( 781): at android.net.LocalSocketImpl.connect(LocalSocketImpl.java:287)
E/UsbDebuggingManager( 781): at android.net.LocalSocket.connect(LocalSocket.java:130)
E/UsbDebuggingManager( 781): at com.android.server.usb.UsbDebuggingManager.listenToSocket(UsbDebuggingManager.java:75)
E/UsbDebuggingManager( 781): at com.android.server.usb.UsbDebuggingManager.run(UsbDebuggingManager.java:111)
E/UsbDebuggingManager( 781): at java.lang.Thread.run(Thread.java:841)
D/dalvikvm( 781): GC_FOR_ALLOC freed 1069K,14% free 31156K/35896K,paused 54ms,total 55ms
V/SearchControllerCache( 2819): creating SearchController
W/Sidekick_LocationOracleImpl( 2819): Best location was null
D/dalvikvm( 2819): GC_FOR_ALLOC freed 514K,5% free 18100K/18940K,paused 15ms,total 15ms
D/audio_hw_primary( 182): select_devices: out_snd_device(0: ) in_snd_device(35: voice-rec-mic)
D/ ( 182): Failed to fetch the lookup information of the device 0000003E
E/ACDB-LOADER( 182): Error: ACDB AudProc vol returned = -19
I/SearchController( 2819): #onHotwordDetectorStarted
D/MainActivity( 5092): ASSERT registerPhone and register =false
D/MainActivity( 5092): ASSERT registerSms and register =false
I/WroxAccessory( 5092): disconnect
D/AndroidRuntime( 5092): Shutting down VM
W/dalvikvm( 5092): threadid=1: thread exiting with uncaught exception (group=0x41e7cba8)
E/AndroidRuntime( 5092): FATAL EXCEPTION: main
E/AndroidRuntime( 5092): Process: ca.foo,PID: 5092
E/AndroidRuntime( 5092): java.lang.RuntimeException: Unable to destroy activity {ca.foo/ca.foo.MainActivity}: java.lang.IllegalArgumentException: Receiver not registered: com.wiley.wroxaccessories.UsbConnection12$1@42f0be28
E/AndroidRuntime( 5092): at android.app.ActivityThread.performDestroyActivity(ActivityThread.java:3497)
E/AndroidRuntime( 5092): at android.app.ActivityThread.handleDestroyActivity(ActivityThread.java:3515)
E/AndroidRuntime( 5092): at android.app.ActivityThread.access$1400(ActivityThread.java:135)
E/AndroidRuntime( 5092): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1249)
E/AndroidRuntime( 5092): at android.os.Handler.dispatchMessage(Handler.java:102)
E/AndroidRuntime( 5092): at android.os.Looper.loop(Looper.java:136)
E/AndroidRuntime( 5092): at android.app.ActivityThread.main(ActivityThread.java:5017)
E/AndroidRuntime( 5092): at java.lang.reflect.Method.invokeNative(Native Method)
E/AndroidRuntime( 5092): at java.lang.reflect.Method.invoke(Method.java:515)
E/AndroidRuntime( 5092): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
E/AndroidRuntime( 5092): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
E/AndroidRuntime( 5092): at dalvik.system.NativeStart.main(Native Method)
E/AndroidRuntime( 5092): Caused by: java.lang.IllegalArgumentException: Receiver not registered: com.wiley.wroxaccessories.UsbConnection12$1@42f0be28
E/AndroidRuntime( 5092): at android.app.LoadedApk.forgetReceiverDispatcher(LoadedApk.java:667)
E/AndroidRuntime( 5092): at android.app.ContextImpl.unregisterReceiver(ContextImpl.java:1453)
E/AndroidRuntime( 5092): at android.content.ContextWrapper.unregisterReceiver(ContextWrapper.java:489)
E/AndroidRuntime( 5092): at com.wiley.wroxaccessories.UsbConnection12.close(UsbConnection12.java:115)
E/AndroidRuntime( 5092): at ca.foo.MainActivity.onDestroy(MainActivity.java:164)
E/AndroidRuntime( 5092): at android.app.Activity.performDestroy(Activity.java:5403)
E/AndroidRuntime( 5092): at android.app.Instrumentation.callActivityOnDestroy(Instrumentation.java:1117)
E/AndroidRuntime( 5092): at android.app.ActivityThread.performDestroyActivity(ActivityThread.java:3484)
E/AndroidRuntime( 5092): ... 11 more
最佳答案
对于抛出的IO错误,
我碰到:
原文链接:https://www.f2er.com/android/431005.html我碰到:
https://code.google.com/p/android/issues/detail?id=20545
一个选项是在onPause()中编写一个函数,
但更好的方法是:(如同一链接中#9所述) –
使用http://developer.android.com/guide/topics/manifest/activity-element.html#lmode
此外,还有一个问题是要正确关闭USB配件连接,这对您的情况有帮助
Proper way to close a USB accessory connection