如果我想要获得所有USB电缆的广播,那么在资源XML文件和清单中做些什么。当前,资源XML文件如下所示:
<resources>
<usb-accessory manufacturer="Acme, Inc" model="Whiz Banger" version="7.0" />
</resources>发布于 2012-11-30 19:43:17
把这个添加到你的舱单上
<receiver android:name=".YourReceiverClassName">
<intent-filter>
<action android:name="android.intent.action.UMS_CONNECTED" />
<action android:name="android.intent.action.UMS_DISCONNECTED" />
</intent-filter>
</receiver>将onReceive内部的yourReceiverClassName修改为
public void onReceive(Context context, Intent intent) {
if (intent.getAction().equalsIgnoreCase( "android.intent.action.UMS_CONNECTED"))
{
Log.d(TAG,"USB connected..");
}
if (intent.getAction().equalsIgnoreCase( "android.intent.action.UMS_DISCONNECTED"))
{
Log.d(TAG,"USB connected..");
}}
https://stackoverflow.com/questions/13651881
复制相似问题