public void toggleConnect(View view) { if (!mConnected) { mBluetoothLeService.connect(mDeviceAddress); } else { mBluetoothLeService.disconnect(); } }
void buttonScanOnClickProcess() { switch (mConnectionState) { case isNull: mConnectionState = connectionStateEnum.isScanning; onConectionStateChange(mConnectionState); scanLeDevice(true); mScanDeviceDialog.show(); break; case isToScan: mConnectionState = connectionStateEnum.isScanning; onConectionStateChange(mConnectionState); scanLeDevice(true); mScanDeviceDialog.show(); break; case isScanning: break; case isConnecting: break; case isConnected: mBluetoothLeService.disconnect(); mHandler.postDelayed(mDisonnectingOverTimeRunnable, 10000); // mBluetoothLeService.close(); mConnectionState = connectionStateEnum.isDisconnecting; onConectionStateChange(mConnectionState); break; case isDisconnecting: break; default: break; } }
@Override protected void onDestroy() { super.onDestroy(); // disconnect from bluetooth device mBluetoothLeService.disconnect(); // unbind the bleservice unbindService(mServiceConnection); // close gattServer mBluetoothLeService.close(); }
@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); }
public void onPauseProcess() { System.out.println("BLUNOActivity onPause"); scanLeDevice(false); mainContext.unregisterReceiver(mGattUpdateReceiver); mLeDeviceListAdapter.clear(); mConnectionState = connectionStateEnum.isToScan; onConectionStateChange(mConnectionState); mScanDeviceDialog.dismiss(); if (mBluetoothLeService != null) { mBluetoothLeService.disconnect(); mHandler.postDelayed(mDisonnectingOverTimeRunnable, 10000); // mBluetoothLeService.close(); } mSCharacteristic = null; }
@Override public boolean onOptionsItemSelected(MenuItem item) { // Handle action bar item clicks here. The action bar will // automatically handle clicks on the Home/Up button, so long // as you specify a parent activity in AndroidManifest.xml. int id = item.getItemId(); //noinspection SimplifiableIfStatement if (id == R.id.action_settings) { return true; } else if (id == R.id.action_devices) { mBluetoothLeService.disconnect(); // Intent intent = new Intent(this, DeviceScanActivityy.class); // startActivity(intent); } return super.onOptionsItemSelected(item); }