コード例 #1
0
 @Override
 protected void onDestroy() {
   if (mGatt == null) {
     return;
   }
   mGatt.close();
   mGatt = null;
   super.onDestroy();
 }
コード例 #2
0
 @Override
 public void onConnectionStateChange(BluetoothGatt gatt, int status, int newState) {
   Log.i("onConnectionStateChange", "Status: " + status);
   switch (newState) {
     case BluetoothProfile.STATE_CONNECTED:
       Log.i("gattCallback", "STATE_CONNECTED");
       gatt.discoverServices();
       break;
     case BluetoothProfile.STATE_DISCONNECTED:
       Log.e("gattCallback", "STATE_DISCONNECTED");
       break;
     default:
       Log.e("gattCallback", "STATE_OTHER");
   }
 }
コード例 #3
0
 @Override
 public void onCharacteristicRead(
     BluetoothGatt gatt, BluetoothGattCharacteristic characteristic, int status) {
   Log.i("onCharacteristicRead", characteristic.toString());
   gatt.disconnect();
 }
コード例 #4
0
 @Override
 public void onServicesDiscovered(BluetoothGatt gatt, int status) {
   List<BluetoothGattService> services = gatt.getServices();
   Log.i("onServicesDiscovered", services.toString());
   gatt.readCharacteristic(services.get(1).getCharacteristics().get(0));
 }