Home > Mobile >  Call connectGatt cannot enter correction (BluetoothGattCallback mGattCallback)
Call connectGatt cannot enter correction (BluetoothGattCallback mGattCallback)

Time:12-05

 mBluetoothGatt=selectDevice. ConnectGatt (MainActivity. This false, mGattCallback); 
Toast. MakeText (MainActivity. This mBluetoothGatt. The toString (), Toast. LENGTH_SHORT), show ();

1, I call connectGatt (), the returned BluetoothGatt object exists,
ConnectGatt 2, call () connection before other phone search is get, I need to connect equipment after the call, I need to connect other mobile search is less than the equipment, it shows that my mobile phone has been connected devices yeah,

Problem is not to the callback function is how to return a responsibility, and here are my callback function:
 private final BluetoothGattCallback mGattCallback=new BluetoothGattCallback () {
@ Override
Public void onConnectionStateChange (BluetoothGatt gatt, int status, int newState because) {
Toast. MakeText (MainActivity. This "bleCallback", Toast. LENGTH_SHORT), show ();
If (newState because==BluetoothProfile. STATE_CONNECTED) {
//bluetooth connected
//search GATT service
MBluetoothGatt. DiscoverServices ();
Toast. MakeText (MainActivity. This "Link successed, Toast. LENGTH_SHORT), show ();

} else if (newState because==BluetoothProfile STATE_DISCONNECTED) {
//bluetooth disconnected
Toast. MakeText (MainActivity. This Link "break", Toast. LENGTH_SHORT), show ();
}
}

@ Override
Public void onServicesDiscovered (BluetoothGatt gatt, int status) {
Toast. MakeText (MainActivity. This "serv disc", Toast. LENGTH_SHORT), show ();
//found the GATT service
If (status==BluetoothGatt. GATT_SUCCESS) {
//setBleNotification ();
}
}

@ Override
Public void onCharacteristicChanged (BluetoothGatt gatt, BluetoothGattCharacteristic characteristic) {
//received data
}
};
  • Related