tags:

views:

72

answers:

1

I've written an Android application and I would like the application to be able to recognize when the Android device is plugged into a PC via the USB or even better, know when it is connected and adb logcat is running. Is this possible?

My purpose is to write traces to a separate circular buffer (which would get written to the sdcard occasionally) except when the device is connected e.g., via Eclipse and logcat is running - in that case, I would like to display the traces as part of logcat as they occur.

+1  A: 

According to the Intent doc, you have several intents fired related to USB Storage:

ACTION_MEDIA_SHARED
Broadcast Action: External media is unmounted because it is being shared via USB mass storage.

ACTION_UMS_CONNECTED
Broadcast Action: The device has entered USB Mass Storage mode.

ACTION_UMS_DISCONNECTED Broadcast Action: The device has exited USB Mass Storage mode.

You can write a broadcast receiver to know when the device will be connected via USB.

Hope this helped.

ccheneson
Thanks for the reply ccheneson. I saw these actions in the intent doc but - to be more specific - I would really like to know whether adb/logcat is running in order to know when to output trace data to logcat instead of a trace file. Is that possible?
dchappelle
UNfortunately, i have no idea. will think about it
ccheneson