简体   繁体   English

Ble信标配对在棉花糖中不起作用

[英]Ble Beacon Pairing is not working in Marshmallow

For my application, I'm trying to programmatically pair with Ble Beacon using BluetoothGatt API.I can able to pair with Ble beacon up to lollipop.But i cannot pair in Marshmallow(My testing device is oneplus 3). 对于我的应用程序,我正在尝试使用BluetoothGatt API以编程方式与Ble Beacon配对。我能够与Ble Beacon配对至棒棒糖。但是我无法在棉花糖中配对(我的测试设备是oneplus 3)。

Also, i gave ACCESS_COARSE_LOCATION,ACCESS_FINE_LOCATION permission in the manifest file and turned on GPS location. 另外,我在清单文件中授予了ACCESS_COARSE_LOCATION,ACCESS_FINE_LOCATION权限,并打开了GPS位置。

BluetoothGatt mGatt; 
baBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
public void connectToDevice(String sMacId) {        

    BluetoothDevice device = baBluetoothAdapter.getRemoteDevice(sMacId);       

    if (mGatt == null) {
        mGatt = device.connectGatt(this, false, gattCallback);
    }
}

This is my BluetoothGatt callback method.After calling discoverServices(),it is directly going to BluetoothProfile.STATE_DISCONNECTED case. 这是我的BluetoothGatt回调方法。调用discoverServices()之后,将直接转到BluetoothProfile.STATE_DISCONNECTED情况。

private final BluetoothGattCallback gattCallback = new BluetoothGattCallback() {
    @Override
    public void onConnectionStateChange(BluetoothGatt gatt, int status, int newState) {

        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");
        }
    }
}

I also tried in native bluetooth.But it showing error.My beacon pairing password is 123456.This password is working less than marshmallow.Please help me! 我也尝试使用本机蓝牙,但是显示错误。我的信标配对密码是123456.此密码的作用不及棉花糖。请帮帮我! Please see this image link 请看这张图片链接

If someone is still looking for a solution for this, see this answer on stackoverflow.com adding gatt.connect() after mDevice.connectGatt(mContext, false, mBluetoothGattCallback); 如果有人仍在寻找解决方案,请在stackoverflow.com上查看此答案 ,在mDevice.connectGatt(mContext, false, mBluetoothGattCallback);之后添加gatt.connect() mDevice.connectGatt(mContext, false, mBluetoothGattCallback); did the trick. 做到了。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM