概述
您是否通过意图请求许可来查看附件?
您是定义自己的自定义类型和通信层还是试图通过adb ....这样做?更多信息可能会很好。但现在,您需要知道您是否可以看到该设备。
private void checkInfo() {
manager = (UsbManager) getSystemService(Context.USB_SERVICE);
/*
* this block required if you need to communicate to USB devices it's
* take permission to device
* if you want than you can set this to which device you want to communicate
*/
// ------------------------------------------------------------------
mPermissionIntent = PendingIntent.getBroadcast(this, 0, new Intent(
ACTION_USB_PERMISSION), 0);
IntentFilter filter = new IntentFilter(ACTION_USB_PERMISSION);
registerReceiver(mUsbReceiver, filter);
// -------------------------------------------------------------------
HashMap deviceList = manager.getDeviceList();
Iterator deviceIterator = deviceList.values().iterator();
String i = "";
while (deviceIterator.hasNext()) {
device = deviceIterator.next();
manager.requestPermission(device, mPermissionIntent);
i += "n" + "DeviceID: " + device.getDeviceId() + "n"
+ "DeviceName: " + device.getDeviceName() + "n"
+ "DeviceClass: " + device.getDeviceClass() + " - "
+ "DeviceSubClass: " + device.getDeviceSubclass() + "n"
+ "VendorID: " + device.getVendorId() + "n"
+ "ProductID: " + device.getProductId() + "n";
}
textInfo.setText(i);
}
private final BroadcastReceiver mUsbReceiver = new BroadcastReceiver() {
public void onReceive(Context context, Intent intent) {
String action = intent.getAction();
if (ACTION_USB_PERMISSION.equals(action)) {
synchronized (this) {
UsbDevice device = (UsbDevice) intent
.getParcelableExtra(UsbManager.EXTRA_DEVICE);
if (intent.getBooleanExtra(
UsbManager.EXTRA_PERMISSION_GRANTED, false)) {
if (device != null) {
// call method to set up device communication
}
} else {
Log.d("ERROR", "permission denied for device " + device);
}
}
}
}
}; :
https://source.android.com/devices/accessories/aoa2.html
文本从复制
最后
以上就是会撒娇猎豹为你收集整理的android aoa usb,建立通过USB连接线使用AOA protocal两款Android设备的全部内容,希望文章能够帮你解决android aoa usb,建立通过USB连接线使用AOA protocal两款Android设备所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
发表评论 取消回复