Feature for getSystemAvailableFeatures() and hasSystemFeature(String).
The device supports connecting to USB accessories.
Constant Value: "android.hardware.usb.accessory"
1. Get a PackageManager Instance named myPackageManager.
Constant Value: "android.hardware.usb.accessory"
1. Get a PackageManager Instance named myPackageManager.
2. Create a Boolean Variable named bolUSBSupported.
3. Set the Minimum and Target SDK version to 12 or greater.
4. In the onCreate method, add the below code. This will return the USB availability to a boolean named bolUSBSupported. It will then display a toast displaying the USB availability of the device to the user.
bolUSBSupported = myPackageManager.hasSystemFeature(PackageManager.FEATURE_USB_ACCESSORY);
if (bolUSBSupported) {
Toast.makeText(this, "Device supports USB", Toast.LENGTH_LONG).show();
} else {
Toast.makeText(this, "Device does NOT support USB!", Toast.LENGTH_LONG).show();
}
5. Compile and run!
Resources:
http://developer.android.com/reference/android/content/pm/PackageManager.html#FEATURE_USB_ACCESSORY
http://developer.android.com/reference/android/content/pm/PackageManager.html#FEATURE_USB_ACCESSORY