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