private boolean isDisconnected(BluetoothGatt bluetoothGatt) { return bluetoothManager.getConnectionState(bluetoothGatt.getDevice(), BluetoothProfile.GATT) == BluetoothProfile.STATE_DISCONNECTED; }
public void attemptConnection() { mBluetoothManager = (BluetoothManager) getSystemService(Context.BLUETOOTH_SERVICE); if (device != null) { details.append("\nConnection state: " + " Device is not null"); mConnectionState = mBluetoothManager.getConnectionState(device, BluetoothProfile.GATT); } Log.i(TAG, "Connection state: " + mConnectionState); details.append("\nConnection state: " + mConnectionState); if (mConnectionState == STATE_DISCONNECTED || mConnectionState == STATE_DISCONNECTING) { ActiveBluetoothDevice btDevice = new Select().from(ActiveBluetoothDevice.class) .orderBy("_ID desc") .executeSingle(); if (btDevice != null) { details.append("\nBT Device: " + btDevice.name); mDeviceName = btDevice.name; mDeviceAddress = btDevice.address; mBluetoothAdapter = mBluetoothManager.getAdapter(); boolean newConnection = true; if(newConnection) { is_connected = connect(mDeviceAddress); details.append("\nConnecting...: "); } } } }
public void attemptConnection() { mBluetoothManager = (BluetoothManager) getSystemService(Context.BLUETOOTH_SERVICE); if (device != null) { details.append("\nConnection state: " + " Device is not null"); mConnectionState = mBluetoothManager.getConnectionState(device, BluetoothProfile.GATT); } Log.i(TAG, "Connection state: " + mConnectionState); details.append("\nConnection state: " + mConnectionState); if (mConnectionState == STATE_DISCONNECTED || mConnectionState == STATE_DISCONNECTING) { ActiveBluetoothDevice btDevice = new Select().from(ActiveBluetoothDevice.class) .orderBy("_ID desc") .executeSingle(); if (btDevice != null) { details.append("\nBT Device: " + btDevice.name); mDeviceName = btDevice.name; mDeviceAddress = btDevice.address; mBluetoothAdapter = mBluetoothManager.getAdapter(); boolean newConnection = true; if(newConnection) { is_connected = connect(mDeviceAddress); details.append("\nConnecting...: "); } } } }
public static void hookBluetoothTile(Object tile) { String summary = ResourceUtils.getInstance().getString(R.string.disabled); BluetoothAdapter bluetoothAdapter = BluetoothAdapter.getDefaultAdapter(); if (bluetoothAdapter.isEnabled()) { summary = bluetoothAdapter.getName(); // TODO this returns the devices name if (summary == null) { summary = bluetoothAdapter.getAddress(); } try { //TODO Why isn't this working? String address = bluetoothAdapter.getAddress(); BluetoothDevice device = bluetoothAdapter.getRemoteDevice(address); int connectionState = bluetoothManager.getConnectionState(device, BluetoothProfile.GATT); if (connectionState == BluetoothGatt.STATE_CONNECTED) { summary = "Connected"; //TODO Display the connected device name } else if (connectionState == BluetoothGatt.STATE_DISCONNECTED) { summary = "Disconnected"; } else if (connectionState == BluetoothGatt.STATE_CONNECTING) { summary = "Connected"; } else if (connectionState == BluetoothGatt.STATE_DISCONNECTING) { summary = "Disconnected"; } } catch (NullPointerException e) { XposedHook.logE(TAG, "Error hooking bluetooth tile", e); } } XposedHelpers.setObjectField(tile, "summary", summary); }