So to alleviate the issue of having to grant permission every time the app is launched, I've followed this answer
So I have my device filter setup
<resources>
<usb-device vendor-id="1234" product-id="5678" />
</resources>
The activity in the manifest
<activity
android:name=".demo.Activity"
android:configChanges="orientation|keyboardHidden|screenSize"
android:label="@string/title_demo"
android:theme="@style/FullscreenTheme">
<intent-filter>
<action android:name="android.hardware.usb.action.USB_DEVICE_ATTACHED" />
</intent-filter>
<meta-data
android:name="android.hardware.usb.action.USB_DEVICE_ATTACHED"
android:resource="@xml/usb_device_filter" />
</activity>
Then in my java file
private final BroadcastReceiver mUsbReceiver = new BroadcastReceiver()
{
public void onReceive(Context context, Intent intent)
{
String action = intent.getAction();
if (ACTION_USB_PERMISSION.equals(action))
{
synchronized (this)
{
UsbDevice device = (UsbDevice)intent.getParcelableExtra(UsbManager.EXTRA_DEVICE);
if(device != null)
{
checkDevice();
}
}
}
}
};
IntentFilter filter = new IntentFilter(ACTION_USB_PERMISSION);
mContext.registerReceiver(mUsbReceiver, filter);
If I start the app with the device connected, it doesn't light up and the API for the device won't communicate with it (it does show in the UsbManager.getDeviceList()
call, however)
As soon as I physically remove it and plug it back in again, it works
Is there a way I can 'reconnect' the device programatically, or some other fix? Thanks