I\'m trying to detect usb devices which are already connected to android. I understand there are actions to detect when USB is either attached or detached. But I don\'t rea
The answer from "Christopher Garza" is probably in Kotlin. I'll send you the code but in Java.
String actionString = getApplicationContext().getPackageName() + ".action.USB_PERMISSION";
PendingIntent mPermissionIntent = PendingIntent.getBroadcast(getApplicationContext(), 0, new
Intent(actionString), 0);
You can remove "getApplicationContext()" if you are pasting this code in an Activity. Otherwise if you are pasting this in other class not specified with an Activity, then you need some sort of this code:
public class Example {
private Context context;
public Example(Context context) {
this.context = context;
}
}