Android 除非附件应用程序关闭,否则不接收附加的操作\u USB\u附件\u
我已将我的应用程序清单设置为使用com.android.future.usb.accessory库,并附加了usb_accessory_过滤器:Android 除非附件应用程序关闭,否则不接收附加的操作\u USB\u附件\u,android,usb,Android,Usb,我已将我的应用程序清单设置为使用com.android.future.usb.accessory库,并附加了usb_accessory_过滤器: <application ... <uses-library android:name="com.android.future.usb.accessory" /> <activity android:name="com.example.usb.MainActivity"
<application
...
<uses-library android:name="com.android.future.usb.accessory" />
<activity
android:name="com.example.usb.MainActivity"
...
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<intent-filter>
<action android:name="android.hardware.usb.action.USB_ACCESSORY_ATTACHED" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<meta-data android:name="android.hardware.usb.action.USB_ACCESSORY_ATTACHED"
android:resource="@xml/accessory_filter" />
</activity>
...
</application>
出于某种原因,只有当我想要连接的应用程序没有在其他设备上运行时,我才会收到此意向。有人知道原因吗,或者有解决办法吗?操作\u USB\u附件\u有点不可靠--请查看以下答案:
protected void onNewIntent(Intent intent) {
String action = intent.getAction();
Log.d(TAG, "New Intent Action " + action);
if (UsbManager.ACTION_USB_ACCESSORY_ATTACHED.equals(action)) {
Toast.makeText(getBaseContext(), "Device Attached", Toast.LENGTH_LONG).show();
}
super.onNewIntent(intent);
}