@RequiresApi(21) private void initializeWithContext(Context context) { if (this.mAdapter == null || this.mLocalBroadcastManager == null) { BluetoothManager manager = (BluetoothManager)context.getSystemService(Context.BLUETOOTH_SERVICE); if(manager == null) { throw new NullPointerException("Cannot get BluetoothManager"); } else { this.mAdapter = manager.getAdapter(); this.mLocalBroadcastManager = LocalBroadcastManager.getInstance(context); } } }
private boolean isDisconnected(BluetoothGatt bluetoothGatt) { return bluetoothManager.getConnectionState(bluetoothGatt.getDevice(), BluetoothProfile.GATT) == BluetoothProfile.STATE_DISCONNECTED; }
private void setConnectionStatus() { boolean connected = false; if (mBluetoothManager != null && activeBluetoothDevice != null && (Build.VERSION.SDK_INT >= 18)) { for (BluetoothDevice bluetoothDevice : mBluetoothManager.getConnectedDevices(BluetoothProfile.GATT)) { if (bluetoothDevice.getAddress().compareTo(activeBluetoothDevice.address) == 0) { connected = true; if (collection_method.compareTo("DexcomG5") == 0) { Transmitter defaultTransmitter = new Transmitter(prefs.getString("dex_txid", "ABCDEF")); if (Build.VERSION.SDK_INT >= 18) mBluetoothAdapter = mBluetoothManager.getAdapter(); if (mBluetoothAdapter != null) { Set<BluetoothDevice> pairedDevices = mBluetoothAdapter.getBondedDevices();
final BluetoothAdapter bluetoothAdapter = bluetoothManager.getAdapter(); if (bluetoothAdapter == null) { throw new UnsupportedOperationException("Bluetooth is not available."); gattServer = bluetoothManager.openGattServer(applicationContext, gattServerCallback); if (gattServer == null) { throw new UnsupportedOperationException("gattServer is null, check Bluetooth is ON.");
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...: "); } } } }
BluetoothManager bluetoothManager = (BluetoothManager) mContext.getSystemService(Context.BLUETOOTH_SERVICE); List<BluetoothDevice> devices = bluetoothManager.getConnectedDevices(BluetoothProfile.GATT); for(BluetoothDevice device : devices) { if(device.getType() == BluetoothDevice.DEVICE_TYPE_LE) { ... } }
mGattServer = btMgr.openGattServer(mApplicationContext, mGattServerCallback); if (mGattServer == null) { throw new UnsupportedOperationException("mGattServer is null, check Bluetooth is ON.");
private void setConnectionStatus() { boolean connected = false; if (mBluetoothManager != null && activeBluetoothDevice != null) { for (BluetoothDevice bluetoothDevice : mBluetoothManager.getConnectedDevices(BluetoothProfile.GATT)) { if (bluetoothDevice.getAddress().compareTo(activeBluetoothDevice.address) == 0) { connected = true; if(collection_method.compareTo("DexcomG5") == 0) { Transmitter defaultTransmitter = new Transmitter(prefs.getString("dex_txid", "ABCDEF")); mBluetoothAdapter = mBluetoothManager.getAdapter(); if (mBluetoothAdapter != null) { Set<BluetoothDevice> pairedDevices = mBluetoothAdapter.getBondedDevices();
mAdapter = mManager.getAdapter(); mGattServer = mManager.openGattServer(context, mGattServerCallback);
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 List<BluetoothDevice> getConnectedDevices() { BluetoothManager btManager = (BluetoothManager)getSystemService(BLUETOOTH_SERVICE); return btManager.getConnectedDevices(BluetoothProfile.GATT); }
/** * Opens GATT server and creates 2 services: Link Loss Service and Immediate Alert Service. * The callback is called when initialization is complete. * * @param context the context. * @param callback optional callback notifying when all services has been added. */ public void openGattServer(final Context context, final OnServerOpenCallback callback) { // Is the server already open? if (mBluetoothGattServer != null) { if (callback != null) callback.onGattServerOpen(); return; } mOnServerOpenCallback = callback; final BluetoothManager manager = (BluetoothManager) context.getSystemService(Context.BLUETOOTH_SERVICE); mBluetoothGattServer = manager.openGattServer(context, mGattServerCallbacks); if (mBluetoothGattServer != null) { // Start adding services one by one. The onServiceAdded method will be called when it completes. addImmediateAlertService(); } else { if (callback != null) callback.onGattServerFailed(-1); mOnServerOpenCallback = null; } }
protected BluetoothAdapter getBluetoothAdapter() { try { if (mBluetoothAdapter == null) { // Initializes Bluetooth adapter. final BluetoothManager bluetoothManager = (BluetoothManager) mContext.getApplicationContext().getSystemService(Context.BLUETOOTH_SERVICE); mBluetoothAdapter = bluetoothManager.getAdapter(); if (mBluetoothAdapter == null) { LogManager.w(TAG, "Failed to construct a BluetoothAdapter"); } } } catch (SecurityException e) { // Thrown by Samsung Knox devices if bluetooth access denied for an app LogManager.e(TAG, "Cannot consruct bluetooth adapter. Security Exception"); } return mBluetoothAdapter; }
private void setConnectionStatus() { boolean connected = false; if (mBluetoothManager != null && activeBluetoothDevice != null && (Build.VERSION.SDK_INT >= 18)) { for (BluetoothDevice bluetoothDevice : mBluetoothManager.getConnectedDevices(BluetoothProfile.GATT)) { if (bluetoothDevice.getAddress().compareTo(activeBluetoothDevice.address) == 0) { connected = true; if (collection_method.compareTo("DexcomG5") == 0) { Transmitter defaultTransmitter = new Transmitter(prefs.getString("dex_txid", "ABCDEF")); if (Build.VERSION.SDK_INT >= 18) mBluetoothAdapter = mBluetoothManager.getAdapter(); if (mBluetoothAdapter != null) { Set<BluetoothDevice> pairedDevices = mBluetoothAdapter.getBondedDevices();
if (null == mBluetoothManager.getAdapter()) { log("No Bluetooth adapter"); return false; mGattServer = mBluetoothManager.openGattServer(context, this); if (null == mGattServer) { log("Failed to open GATT server");
BTDeviceTracker(Context context, BTDeviceConditionData data, @NonNull PendingIntent event_positive, @NonNull PendingIntent event_negative) { super(context, data, event_positive, event_negative); if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.JELLY_BEAN_MR2) { BluetoothManager bluetoothManager = (BluetoothManager) context.getSystemService(Context.BLUETOOTH_SERVICE); for (int profile : new int[]{BluetoothProfile.GATT, BluetoothProfile.GATT_SERVER}) { for (BluetoothDevice btDevice : bluetoothManager.getConnectedDevices(profile)) { if (is_target(btDevice)) { matched_devices++; } } } } determine_satisfied(); }
@Inject public BLEPeripheralServer(@ApplicationContext Context context) { ((BLEApplication)context).getApplicationComponent().inject(this); if (supportPeripheralMode()) { mBLEAdvertiser = mBtAdapter.getBluetoothLeAdvertiser(); mGattServer = mBtManager.openGattServer(context, mGattServerCallback); addDeviceInfoService(); } }
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); }
/** * Check if Bluetooth LE is supported by this Android device, and if so, make sure it is enabled. * * @return false if it is supported and not enabled * @throws BleNotAvailableException if Bluetooth LE is not supported. (Note: The Android emulator will do this) */ @TargetApi(18) public boolean checkAvailability() throws BleNotAvailableException { if (!isBleAvailableOrSimulated()) { throw new BleNotAvailableException("Bluetooth LE not supported by this device"); } return ((BluetoothManager) mContext.getSystemService(Context.BLUETOOTH_SERVICE)).getAdapter().isEnabled(); }
private void setConnectionStatus() { boolean connected = false; if (mBluetoothManager != null && activeBluetoothDevice != null) { for (BluetoothDevice bluetoothDevice : mBluetoothManager.getConnectedDevices(BluetoothProfile.GATT)) { if (bluetoothDevice.getAddress().compareTo(activeBluetoothDevice.address) == 0) { connected = true; if(collection_method.compareTo("DexcomG5") == 0) { Transmitter defaultTransmitter = new Transmitter(prefs.getString("dex_txid", "ABCDEF")); mBluetoothAdapter = mBluetoothManager.getAdapter(); if (mBluetoothAdapter != null) { Set<BluetoothDevice> pairedDevices = mBluetoothAdapter.getBondedDevices();