Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Host Mode USB debugging

Tags:

android

usb

I am developing an application where my android phone connects to a USB accessory. However, when the accessory is connected is there any easy way to debug the application?

Can we use a micro usb hub or similar device?

like image 821
user1145533 Avatar asked Dec 03 '12 14:12

user1145533


2 Answers

When debugging applications that use USB accessory or host features, you most likely will have USB hardware connected to your Android-powered device. This will prevent you from having an adb connection to the Android-powered device via USB. You can still access adb over a network connection. To enable adb over a network connection:

  1. Connect the Android-powered device via USB to your computer.
  2. From your SDK platform-tools/ directory, enter adb tcpip 5555 at the command prompt.
  3. Enter adb connect <device-ip-address>:5555 You should now be connected to the Android- powered device and can issue the usual adb commands like adb logcat.
  4. To set your device to listen on USB, enter adb usb.

source: Android developer site

like image 80
Mariusz Chw Avatar answered Sep 23 '22 17:09

Mariusz Chw


You could write an app that reads the logcat output on the phone and displays it on the screen and/or saves it to a file which you can pull with adb afterwards. The app must be given READ_LOGS permission, which you can do with adb shell pm grant com.package.appname android.permission.READ_LOGS (at least on a rooted phone).

Another alternative might be to log over WiFi. adb has an option to connect over TCP/IP, but this is not something I've tried so I don't know how difficult it is to set up or how well it works.

Unless your logs are really verbose it's sometimes enough to run through your USB accessory use-case and then unplug the accessory and connect the phone to your computer to catch the logcat output. The logs are buffered up to a certain amount, so you can get a reasonable amount of logs using this method.

like image 29
Michael Avatar answered Sep 22 '22 17:09

Michael