3

I want to detect whether my android smart phone supports USB On-The-Go . I have searched a lot in the internet but could not find any way to do that !

I have found that there is an application "USB OTG Checker" . Here is some screenshot of that app .

enter image description here

How can I check whether an USB is plugged in smartphone ?

osimer pothe
  • 2,827
  • 14
  • 54
  • 92

2 Answers2

2

Actually USB Host actually similar with OTG,since we can check the USB Host feature programically, here are my solution,hope this help you.

    /**
 * Check the device whether has USB-HOST feature.
 */
public static boolean hasUsbHostFeature(Context context) {
    return context.getPackageManager().hasSystemFeature(PackageManager.FEATURE_USB_HOST);
}
Folyd
  • 1,148
  • 1
  • 16
  • 20
1

your answer is here : https://stackoverflow.com/a/34691806/3818437

add a <uses-feature> element to your manifest, indicating that you are interested in the android.hardware.usb.host feature.

OR use PackageManager, hasSystemFeature(), and FEATURE_USB_HOST. FEATURE_USB_HOST is defined as the same string as you would be using in <uses-feature>(android.hardware.usb.host).

Community
  • 1
  • 1
mhdjazmati
  • 4,152
  • 1
  • 26
  • 37