检查Android的USB连接状态 [英] Check USB Connection Status on Android
问题描述
我在想,如果有可能每次执行一个动作的设备更改的USB状态。
例如,如果用户插入的电缆,它是在同步/充电模式它执行某个动作,如果用户然后手机变成执行另一个操作的USB存储卡模式,并且如果用户然后断开电缆那么另一个操作完成。
这是实际可行的。任何帮助,这将大大AP preciated。
感谢您
这是实际可行的。
当然。
Android的播放各种 意图
,你可以听与的BroadcastReceiver
。其中包括:
-
ACTION_BATTERY_CHANGED
(告诉你,如果设备插入USB或AC) -
ACTION_UMS_CONNECTED
和ACTION_UMS_DISCONNECTED
(告诉你,如果设备进入或离开USB大容量存储模式)
I was wondering if would be possible to perform an action for each time the USB status of the device changes.
For example if the user plugs in the cable and it is in sync/charge mode it performs a certain action, if the user then changes the phone into USB Memory Card mode another action is performed and if the user then disconnects the cable then the another action is done.
Is this actually possible. Any help with this would be greatly appreciated.
Thank you
Is this actually possible.
Sure.
Android broadcasts various Intents
that you can listen to with a BroadcastReceiver
. Among these are:
ACTION_BATTERY_CHANGED
(tells you if device is plugged into USB or AC)ACTION_UMS_CONNECTED
andACTION_UMS_DISCONNECTED
(tells you if device enters or leaves USB Mass Storage mode)
这篇关于检查Android的USB连接状态的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!