List of usage examples for android.bluetooth BluetoothManager getConnectedDevices
@RequiresPermission(Manifest.permission.BLUETOOTH) public List<BluetoothDevice> getConnectedDevices(int profile)
From source file:com.google.android.apps.forscience.ble.MyBleService.java
@Override public void onCreate() { super.onCreate(); mDeviceListeners = new ArrayList<BleDeviceListener>(); bleDevices = new BleDevices() { @Override//from w w w. ja v a 2 s.co m public void onDeviceAdded(BluetoothDevice device, int rssi, byte[] scanRecord) { for (BleDeviceListener listener : mDeviceListeners) { listener.onDeviceAdded(device); } } @Override public void onDeviceRemoved(BluetoothDevice device) { for (BleDeviceListener listener : mDeviceListeners) { listener.onDeviceRemoved(device); } } }; handler = new Handler(new Handler.Callback() { @Override public boolean handleMessage(Message msg) { if (MSG_PRUNE == msg.what && bleDevices != null) { Log.v(TAG, "Pruning devices"); BluetoothManager manager = (BluetoothManager) getSystemService(Context.BLUETOOTH_SERVICE); bleDevices.pruneOldDevices(manager.getConnectedDevices(BluetoothProfile.GATT)); } return false; } }); }