如果我想要为所有USB电缆广播,可以在资源XML文件和清单中执行什么操作。 目前资源XML文件是这样的:
<resources>
<usb-accessory manufacturer="Acme, Inc" model="Whiz Banger" version="7.0" />
</resources>
答案 0 :(得分:2)
将此添加到您的清单
<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>
将yourReceiverClassName内的onReceive修改为此
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..");
}
}