Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/visual-studio-2012/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用AOA协议通过USB电缆在两个android设备之间建立通信_Android - Fatal编程技术网

使用AOA协议通过USB电缆在两个android设备之间建立通信

使用AOA协议通过USB电缆在两个android设备之间建立通信,android,Android,我正在尝试通过USB OTG电缆连接两台带有API 14+的Android设备 但是当我访问两个API时,我得到了null值,如下所示 mUsbManager.getDeviceList(); mUsbManager.getAccessoryList(); 请帮助我分享您的想法或任何示例应用程序(如果您有)。您是否出于查看附件的目的而请求许可 您是在定义自己的自定义类型和通信层,还是试图通过adb来定义。。。。?更多信息在这里可能是好的。不过现在,你需要知道你是否能看到这个设备 该问题在AO

我正在尝试通过USB OTG电缆连接两台带有API 14+的Android设备

但是当我访问两个
API
时,我得到了
null
值,如下所示

mUsbManager.getDeviceList();

mUsbManager.getAccessoryList();

请帮助我分享您的想法或任何示例应用程序(如果您有)。

您是否出于查看附件的目的而请求许可

您是在定义自己的自定义类型和通信层,还是试图通过adb来定义。。。。?更多信息在这里可能是好的。不过现在,你需要知道你是否能看到这个设备

该问题在AOA v2页面中有所定义:

文本复制自:

private void checkInfo(){
manager=(UsbManager)getSystemService(Context.USB_服务);
/*
*如果需要与USB设备通信,则需要此块
*获取设备的许可
*如果需要,可以将其设置为要与哪个设备通信
*/
// ------------------------------------------------------------------
mPermissionIntent=PendingIntent.getBroadcast(此,0,新Intent(
操作(USB权限),0);
IntentFilter筛选器=新建IntentFilter(操作\u USB\u权限);
寄存器接收器(mUsbReceiver,过滤器);
// -------------------------------------------------------------------
HashMap deviceList=manager.getDeviceList();
迭代器deviceIterator=deviceList.values().Iterator();
字符串i=“”;
while(deviceIterator.hasNext()){
device=deviceIterator.next();
manager.requestPermission(设备、mPermissionIntent);
i+=“\n”+“设备ID:”+device.getDeviceId()+“\n”
+DeviceName:“+device.getDeviceName()+”\n
+“DeviceClass:+设备。getDeviceClass()+”-“
+DeviceSubClass:“+device.getDeviceSubclass()+”\n
+VendorID:“+device.getVendorId()+”\n
+ProductID:“+device.getProductId()+”\n”;
}
textInfo.setText(i);
}
专用最终广播接收器mUsbReceiver=新广播接收器(){
公共void onReceive(上下文、意图){
String action=intent.getAction();
if(动作\u USB\u权限等于(动作)){
已同步(此){
UsbDevice设备=(UsbDevice)意图
.getParcelableExtra(UsbManager.EXTRA_设备);
if(intent.getBooleanExtra)(
UsbManager.EXTRA_权限(已授予,错误)){
如果(设备!=null){
//调用方法来设置设备通信
}
}否则{
Log.d(“错误”,“设备的权限被拒绝”+设备);
}
}
}
}
};
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<string , UsbDevice> deviceList = manager.getDeviceList();
        Iterator<usbdevice> 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);
                    }
                }
            }
        }
};