Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/212.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 BluetoothGatt api未与棉花糖中的ibeacon配对_Android_Bluetooth Lowenergy_Android 6.0 Marshmallow_Ibeacon Android_Bluetooth Gatt - Fatal编程技术网

Android BluetoothGatt api未与棉花糖中的ibeacon配对

Android BluetoothGatt api未与棉花糖中的ibeacon配对,android,bluetooth-lowenergy,android-6.0-marshmallow,ibeacon-android,bluetooth-gatt,Android,Bluetooth Lowenergy,Android 6.0 Marshmallow,Ibeacon Android,Bluetooth Gatt,我尝试在android中使用BluetoothGatt API以编程方式与Ble iBeacon配对。我可以与Ble iBeacon配对到棒棒糖。但我不能在棉花糖中配对(我的测试设备是oneplus 3)。我使用altbeacon库进行信标扫描 此外,我在清单文件中授予了访问粗略位置、访问精细位置权限,并启用了GPS位置 private BluetoothGatt mGatt; BluetoothAdapter baBluetoothAdapter; @Override protected vo

我尝试在android中使用BluetoothGatt API以编程方式与Ble iBeacon配对。我可以与Ble iBeacon配对到棒棒糖。但我不能在棉花糖中配对(我的测试设备是oneplus 3)。我使用altbeacon库进行信标扫描

此外,我在清单文件中授予了访问粗略位置、访问精细位置权限,并启用了GPS位置

private BluetoothGatt mGatt;
BluetoothAdapter baBluetoothAdapter;
@Override
protected void onCreate(Bundle savedInstanceState) {
    baBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
    intentFilter = new IntentFilter();
    intentFilter.addAction(BluetoothDevice.ACTION_BOND_STATE_CHANGED);       
    registerReceiver(myReceiver, intentFilter);
}
这是我发送的信标mac id

public void PairToDevice(String sMacId) {

   BluetoothDevice device = baBluetoothAdapter.getRemoteDevice(sMacId);      

    if (mGatt == null) {
        mGatt = device.connectGatt(this, false, gattCallback);
    }
}
private final BluetoothGattCallback gattCallback = new BluetoothGattCallback() {
    @Override
    public void onConnectionStateChange(BluetoothGatt gatt, int status, int newState) {
        Log.i("onConnectionStateChange", "Status: " + status);
        switch (newState) {
            case BluetoothProfile.STATE_CONNECTED:
                Log.e("gattCallback", "STATE_CONNECTED");
                gatt.discoverServices();
                break;
            case BluetoothProfile.STATE_DISCONNECTED:
                Log.e("gattCallback", "STATE_DISCONNECTED");
                break;
            default:
                Log.e("gattCallback", "STATE_OTHER");
        }
    }

    @Override
    public void onCharacteristicChanged(BluetoothGatt gatt, BluetoothGattCharacteristic characteristic) {
        super.onCharacteristicChanged(gatt, characteristic);
    }

    @Override
    public void onServicesDiscovered(BluetoothGatt gatt, int status) {

    }
}
在这里,我正在检查粘合状态。粘合状态在棉花糖中始终为零。但与棉花糖相比,它工作正常

private BroadcastReceiver myReceiver = new BroadcastReceiver() {
    @Override
    public void onReceive(Context context, Intent intent) {
        String action = intent.getAction();
        if (BluetoothDevice.ACTION_BOND_STATE_CHANGED.equals(action)) {
            BluetoothDevice device = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
            int nState = device.getBondState();

            if (nState == BluetoothDevice.BOND_BONDED) {
                Log.e("Bond Information", "device bonded");

            } else if (nState == BluetoothDevice.BOND_BONDING) {
                 Log.e("Bond Information", "device bonding");
            } else if (nState == BluetoothDevice.BOND_NONE) {
                 Log.e("Bond Information", "bond none");
            }
        }
    }
};

请在获得许可的情况下打开蓝牙。您只调用connectGatt,而不调用createBond,这将启动配对。您是否确定Marshmallow上正在调用该设备。connectGatt?我会添加调试来验证。谢谢你的回复。我可以发现这些设备,而且我还可以看到配对对话框。但是我无法配对信标设备。