开发者

How to detect external device in android

开发者 https://www.devze.com 2023-03-07 02:21 出处:网络
I want to write a program to det开发者_StackOverflow中文版ect any external device with which my android phone is connected. eg if I connect to computer to share though usb mass storage or if I connect

I want to write a program to det开发者_StackOverflow中文版ect any external device with which my android phone is connected. eg if I connect to computer to share though usb mass storage or if I connect for charging.

Which API or package in android is responsible for hardware interfaces. How can I detect any of external device if connected to my android phone.


While USB connection is not perfectly synonymous with external power, that might be a reasonable way to detect it for the majority of devices using legacy releases.

The ACTION_BATTERY_CHANGED Intent has constants for both BATTERY_PLUGGED_USB and BATTERY_PLUGGED_AC.

See

http://developer.android.com/reference/android/os/BatteryManager.html

You could also detect the loss of the external storage directory during USB mounting - but bear in mind first that not everyone mounts their external storage when USB connected, and that newer android releases aren't going to do an outright USB mass storage mount at all.


It seems that for 2.3.4 and 3.1 you use USB API.

0

精彩评论

暂无评论...
验证码 换一张
取 消