Example usage for android.bluetooth BluetoothManager getConnectedDevices

List of usage examples for android.bluetooth BluetoothManager getConnectedDevices

Introduction

In this page you can find the example usage for android.bluetooth BluetoothManager getConnectedDevices.

Prototype

@RequiresPermission(Manifest.permission.BLUETOOTH)
public List<BluetoothDevice> getConnectedDevices(int profile) 

Source Link

Document

Get connected devices for the specified profile.

Usage

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;
        }
    });
}