private final BluetoothGattServerCallback mGattServerCallback = new BluetoothGattServerCallback() {
@Override
public void onConnectionStateChange(BluetoothDevice device, final int status, int newState) {
super.onConnectionStateChange(device, status, newState);
if (status == BluetoothGatt.GATT_SUCCESS) {
if (newState == BluetoothGatt.STATE_CONNECTED) {
mBluetoothDevices.add(device);
updateConnectedDevicesStatus();
String macAddress = android.provider.Settings.Secure.getString(getApplication().getContentResolver(), "bluetooth_address");
Log.v(TAG, "Connected to device: " + device.getAddress());
Log.d("/bleUUID","uuid is " +macAddress);
Log.d("/bleUUID","uuid is " +CHARACTERISTIC_USER_DESCRIPTION_UUID);
} else if (newState == BluetoothGatt.STATE_DISCONNECTED) {
mBluetoothDevices.remove(device);
updateConnectedDevicesStatus();
Log.v(TAG, "Disconnected from device");
}
} else {
mBluetoothDevices.remove(device);
updateConnectedDevicesStatus();
// There are too many gatt errors (some of them not even in the documentation) so we just
// show the error to the user.
final String errorMessage = getString(com.efftronics.android.bleperipheral.R.string.status_errorWhenConnecting) + ": " + status;
runOnUiThread(new Runnable() {
@Override
public void run() {
Toast.makeText(Peripheral.this, errorMessage, Toast.LENGTH_LONG).show();
}
});
Log.e(TAG, "Error when connecting: " + status);
}
}
}
从nrf connect断开连接时,此onConnectionStateChange
未调用。为什么?
我正在实现BLE外围应用程序。我的应用是广告(外围模式)。 NRF连接(中央模式)正在扫描广告设备。
当另一个应用程序连接到我的ble外围应用程序时,我的ble围产期应用程序的地址显示在NRF connect中。该地址来自此行。
私有静态最终UUID CHARACTERISTIC_USER_DESCRIPTION_UUID = UUID .fromString(“ 00002901-0000-1000-8000-00805f9b34fb”);
但是每次连接到NRF连接时,此地址都会更改。为什么?
如果我每次都需要相同的地址。我该怎么办?
一段时间后,我的外围设备应用程序会自动断开连接,并显示超时错误。为什么?