private boolean getConnectedBandClient() throws InterruptedException, BandException {
    if (client == null) {
      BandInfo[] devices = BandClientManager.getInstance().getPairedBands();
      if (devices.length == 0) {
        appendToUI("Band isn't paired with your phone.\n", 1);
        return false;
      }
      client = BandClientManager.getInstance().create(getBaseContext(), devices[0]);
    } else if (ConnectionState.CONNECTED == client.getConnectionState()) {
      return true;
    }

    appendToUI("Band is connecting...\n", 1);
    return ConnectionState.CONNECTED == client.connect().await();
  }
예제 #2
0
  private boolean getConnectedBandClient() throws BandException {
    if (client == null) {
      BandInfo[] devices = BandClientManager.getInstance().getPairedBands();
      if (devices.length == 0) {
        Log.e(TAG, "Band isn't paired with your phone.");
        return false;
      }
      client = BandClientManager.getInstance().create(context, devices[0]);
    } else if (ConnectionState.CONNECTED == client.getConnectionState()) {
      return true;
    }

    Log.i(TAG, "Band is connecting...");
    try {
      return ConnectionState.CONNECTED == client.connect().await();
    } catch (InterruptedException e) {
      return false;
    }
  }
 @Override
 public Void doInBackground(Void... params) {
   BandInfo[] pairedBands = BandClientManager.getInstance().getPairedBands();
   if (pairedBands.length == 0) {
     showNotPaired();
   } else {
     client =
         BandClientManager.getInstance().create(HeartRateConsentActivity.this, pairedBands[0]);
     try {
       if (client.connect().await() == ConnectionState.CONNECTED) {
         client
             .getSensorManager()
             .requestHeartRateConsent(
                 HeartRateConsentActivity.this, HeartRateConsentActivity.this);
       }
     } catch (InterruptedException interruptedEx) {
     } catch (BandException bandEx) {
     }
   }
   return null;
 }