The device must be in USB Host mode to use the UsbManager class. However, when checking if the app is in USB Host mode using packagemanager.hasSystemFeature(PackageManager.FEATURE_USB_HOST)
, it always returns false. Apparently, USB Host is an unsupported feature on Chromebooks. Is there another way to detect when a USB is inserted on Android on Chromebooks?
We're transitioning from Chrome App to Android and this documentation says to use a "Temporary* private USB host API" in place of the chrome.usb
feature. But the link is broken and I can't find more information on it.
I've also tried the USB Web API with no results (the app is contained within a webview, so thought it might work).
The solution is to use the
state
property of theStorageVolume
. AStorageMediaState
value ofMOUNTED
will indicate a mounted USB drive. You also need to filter out non-USB drives by using the various properties of the attachedStorageVolume
s.