コード例 #1
0
 @Override
 public void onServiceConnected(ComponentName componentName, IBinder service) {
   mBluetoothLeService = ((BluetoothLeService.LocalBinder) service).getService();
   if (!mBluetoothLeService.initialize()) {
     Log.e(TAG, "Unable to initialize Bluetooth");
     finish();
   }
   // Automatically connects to the device upon successful start-up initialization.
   mBluetoothLeService.connect(mDeviceAddress);
 }
コード例 #2
0
  @Override
  protected void onResume() {
    super.onResume();

    registerReceiver(mGattUpdateReceiver, makeGattUpdateIntentFilter());
    if (mBluetoothLeService != null) {
      final boolean result = mBluetoothLeService.connect(mDeviceAddress);
      Log.d(TAG, "Connect request result=" + result);
    }
  }
コード例 #3
0
 @Override
 public boolean onOptionsItemSelected(MenuItem item) {
   switch (item.getItemId()) {
     case R.id.menu_connect:
       mBluetoothLeService.connect(mDeviceAddress);
       return true;
     case R.id.menu_disconnect:
       mBluetoothLeService.disconnect();
       return true;
     case android.R.id.home:
       onBackPressed();
       return true;
   }
   return super.onOptionsItemSelected(item);
 }