简体   繁体   中英

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).

Also, i gave ACCESS_COARSE_LOCATION,ACCESS_FINE_LOCATION permission in the manifest file and turned on GPS location.

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.

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! 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); did the trick.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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