Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/185.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
Android 找到外围设备,但可以';我无法连接到它_Android_Bluetooth Lowenergy - Fatal编程技术网

Android 找到外围设备,但可以';我无法连接到它

Android 找到外围设备,但可以';我无法连接到它,android,bluetooth-lowenergy,Android,Bluetooth Lowenergy,在我的应用程序中,我可以很好地扫描外围设备,但无法连接到它。以下是连接到主设备的代码: bleGatt = masterDevice.connectGatt(currentContext,false,gattCallback); if(bleGatt == null){ Log.w(TAG,"Unable to create GATT client"); } 如果我将自动连接标志更改为true,如: bleGatt = masterDevice.conn

在我的应用程序中,我可以很好地扫描外围设备,但无法连接到它。以下是连接到主设备的代码:

    bleGatt = masterDevice.connectGatt(currentContext,false,gattCallback);
    if(bleGatt == null){
        Log.w(TAG,"Unable to create GATT client");
    }
如果我将自动连接标志更改为true,如:

bleGatt = masterDevice.connectGatt(currentContext,true,gattCallback);
然后设备会连接,但我的自定义服务和特征不会在ServicesDiscoveryd回调中被发现。我认为这段代码在API大于21的设备上运行有一些问题


任何帮助都将不胜感激,谢谢

运气好吗?有时我可以连接,但有时我的中央设备发现但无法连接。奇怪的