BroadcastReceiver monitoring for a specific USB device attached
If you absolutely have to create your BroadcastReceiver programatically, then you need to filter the devices programatically as well.
Try this:
public void onReceive(Context context, Intent intent)
{
if (intent.getAction().equals(UsbManager.ACTION_USB_DEVICE_DETACHED))
{
UsbDevice d = (UsbDevice)
intent.getExtras().get(UsbManager.EXTRA_DEVICE);
if (d.getVendorId() == MY_VENDOR_ID && d.getDeviceId() == MY_DEVICE_ID)
{
// Your code here
}
}
}
Android external fingerprint USB always returns false on USB permission
Might be the same issue: AndroidStudio USB: EXTRA_PERMISSION_GRANTED returns false - always
Changing PendingIntent.FLAG_IMMUTABLE to PendingIntent.FLAG_MUTABLE helped in my case.
Related Topics
Sending Http Post Request with Android
Android: Specify Two Different Images for Togglebutton Using Xml
Setting a Spinner Onclicklistener() in Android
Android Runtime Permissions- How to Implement
Fatal Exception: Firebase-Messaging-Intent-Handle -- Java.Lang.Noclassdeffounderror
How Many Ways to Convert Bitmap to String and Vice-Versa
Intellij Build Error Context Mismatch
Android Gps Incorrect Location Data on Query
What Does a Java Static Method Look Like in Ruby
Alternative to Jzebra/Qz Java Raw Print Plugin After Npapi Being Dropped on Chrome Browser
Android Resource Not Found Exception
Android: How to Hide Actionbar on Certain Activities
How to Detect a Click in an Ontouch Listener
When Onbindviewholder Is Called and How It Works
Android Httpclient Persistent Cookies
Multiple Dex Files Define <My Package>/Buildconfig, Can't Find the Cause:
How to Combine One Android Studio Project into Another Android Studio Project