同樣遇到這樣的問題,我的Android裝置是原道N12C,官方的4.0.3系統,遇到這個問題,後來找了半天找到的,現在匯總一下吧:
1、建立 android.hardware.usb.host.xml,內容為:
[html]
<permissions>
<feature name="android.hardware.usb.host"/>
</permissions>
<permissions>
<feature name="android.hardware.usb.host"/>
</permissions>將該檔案push到/system/etc/permissions目錄下
2、在/system/etc/permissions下的handheld_core_hardware.xml或者tablet_core_hardware.xml檔案的<permissions>段中添加:
[html]
<feature name="android.hardware.usb.host">
<feature name="android.hardware.usb.host">重啟裝置
3、修改AndroidManifest.xml檔案,添加以下許可權:
[html] ="android.hardware.usb.host" />
<uses-permission android:name="android.hardware.usb.host" />
4、枚舉裝置的代碼例子:
[html]
UsbManager manager = (UsbManager) getSystemService(Context.USB_SERVICE);
HashMap<String, UsbDevice> deviceList = manager.getDeviceList();
Log.e(TAG, "get device list = " + deviceList.size());
Toast.makeText(this, "get device list = " + deviceList.size(), 200).show();
Iterator<UsbDevice> deviceIterator = deviceList.values().iterator();
while (deviceIterator.hasNext()) {
UsbDevice device = deviceIterator.next();
Log.e(TAG, "device name = " + device.getDeviceName());
}
UsbManager manager = (UsbManager) getSystemService(Context.USB_SERVICE);
HashMap<String, UsbDevice> deviceList = manager.getDeviceList();
Log.e(TAG, "get device list = " + deviceList.size());
Toast.makeText(this, "get device list = " + deviceList.size(), 200).show();
Iterator<UsbDevice> deviceIterator = deviceList.values().iterator();
while (deviceIterator.hasNext()) {
UsbDevice device = deviceIterator.next();
Log.e(TAG, "device name = " + device.getDeviceName());
}