コード例 #1
0
 @Override
 protected void onResume() {
   super.onResume();
   registerReceiver(mBleReceiver, BleService.getIntentFilter());
   ArrayList<BleGattService> services = mBle.getServices(mDeviceAddress);
   if (services == null || services.size() == 0) {
     onDeviceDisconnected();
   }
 }
コード例 #2
0
 @Override
 public boolean onChildClick(
     ExpandableListView parent, View v, int groupPosition, int childPosition, long id) {
   Log.d(TAG, "onChildClick " + groupPosition + " " + childPosition);
   if (mGattCharacteristics != null) {
     final BleGattCharacteristic characteristic =
         mGattCharacteristics.get(groupPosition).get(childPosition);
     Intent intent = new Intent(DeviceControlActivity.this, CharacteristicActivity.class);
     intent.putExtra("address", mDeviceAddress);
     Log.d(TAG, "service size " + mBle.getServices(mDeviceAddress).size());
     intent.putExtra(
         "service",
         mBle.getServices(mDeviceAddress).get(groupPosition).getUuid().toString());
     intent.putExtra("characteristic", characteristic.getUuid().toString().toUpperCase());
     startActivity(intent);
     return true;
   }
   return false;
 }
コード例 #3
0
        @Override
        public void onReceive(Context context, Intent intent) {
          Bundle extras = intent.getExtras();
          if (!mDeviceAddress.equals(extras.getString(BleService.EXTRA_ADDR))) {
            return;
          }

          String action = intent.getAction();
          if (BleService.BLE_GATT_CONNECTED.equals(action)) {
            mConnected = true;
            updateConnectionState(R.string.connected);
            invalidateOptionsMenu();
          } else if (BleService.BLE_GATT_DISCONNECTED.equals(action)) {
            onDeviceDisconnected();
          } else if (BleService.BLE_SERVICE_DISCOVERED.equals(action)) {
            displayGattServices(mBle.getServices(mDeviceAddress));
          }
        }