Sense for usb connection, Android

Viewed 33

I am developing an app to retrieve data from an external device via USB. Now I am trying to get my app to sense USB connections

my code is

public boolean isConnected() { Intent intent = registerReceiver(null, new IntentFilter("android.hardware.usb.action.USB_STATE")); System.out.println(intent.getExtras().getBoolean("connected")); return intent.getExtras().getBoolean("connected"); }

However, I saw past questions adding (Context context) to the function like this

public static boolean isConnected(Context context) {

After reading the documentation on USB connections, I still do not understand what is context and how it can be used in this situation, especially when I call the function isConnected(something). Appreciate an explanation and if there are other efficient ways of sensing a USB connection , I would greatly appreciate your help, thank you very much

0 Answers
Related