Exemplo n.º 1
0
  private void stopScan() {
    Log.wtf(TAG, "Stopping scan : " + found);
    found = false;
    mBluetoothAdapter.stopLeScan(this);
    setProgressBarIndeterminateVisibility(false);

    for (BluetoothDevice x : mDevices) {
      if (x.getName() == null) {
      } else if (x.getName().equalsIgnoreCase(deviceName) && !found) {
        found = true;
        Log.wtf(TAG, "Device name is: " + deviceName);
        Log.wtf(TAG, "Device name is: " + "CONNECTING!!!!!");
        if (!leManager.isConnected()) {
          leManager.setDevice(x);
          Log.wtf(TAG, "Device name is: " + "CONNECT!!!!!");
          leManager.connectDevice(4);
        }
        //                BluetoothDevice device = x;
        //                currentDevice = device;
        //                mConnectedGatt = device.connectGatt(this, true, mGattCallback);
        //                mConnectedGatt.requestConnectionPriority(1);
        // Display progress UI
        // mHandler.sendMessage(Message.obtain(null, MSG_PROGRESS, "Connecting to " +
        // device.getName() + "..."));
      }
    }
    if (!found && stillRunning && !leManager.isConnected()) {
      if (!isScanRunning) {
        Log.wtf(TAG, "Restarting scan");
        runOnUiThread(mStartRunnable);
      }
    }
  }
Exemplo n.º 2
0
 public void reconnect(BluetoothDevice d) {
   leManager.setDevice(d);
   Log.wtf(TAG, "Device name is: " + "CONNECT!!!!!");
   leManager.connectDevice(4);
 }