我有一个按钮来启动连接,然后写入Characaristic。这是代码:
public void sendMessage(View view) {
final BluetoothManager bluetoothManager =
(BluetoothManager) getSystemService(Context.BLUETOOTH_SERVICE);
mBluetoothAdapter = bluetoothManager.getAdapter();
BluetoothDevice device = mBluetoothAdapter.getRemoteDevice("Device MAC");
device.connectGatt(this, false, mGattCallback, 2);
//connectToDevice(device);
}
private final BluetoothGattCallback mGattCallback = new BluetoothGattCallback() {
@Override
public void onConnectionStateChange(BluetoothGatt gatt, int status,
int newState) {...
问题是,未调用onConnectionStateChange。我尝试使用反射来建立连接,如下所述:BluetoothDevice.ConnectGatt() with transport parameter 但它不起作用。这是我在调试控制台中得到的结果:
D / BluetoothGatt:onClientRegistered() - status = 0 clientIf = 12 D / BluetoothGatt:onClientConnectionState() - status = 0 clientIf = 12 device = 8E:4D:4B:10:AC:E6 D / BluetoothGatt:onClientConnParamsChanged() - Device = 8E:4D:4B:10:AC:E6 interval = 6 status = 0 D / BluetoothGatt:onClientConnParamsChanged() - Device = 8E:4D:4B:10:AC:E6 interval = 30 status = 0
有什么建议吗?感谢。