Example usage for android.bluetooth BluetoothAdapter getRemoteDevice

List of usage examples for android.bluetooth BluetoothAdapter getRemoteDevice

Introduction

In this page you can find the example usage for android.bluetooth BluetoothAdapter getRemoteDevice.

Prototype

public BluetoothDevice getRemoteDevice(byte[] address) 

Source Link

Document

Get a BluetoothDevice object for the given Bluetooth hardware address.

Usage

From source file:com.evothings.BLE.java

private void connect(final CordovaArgs args, final CallbackContext callbackContext) {
    final BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter();
    checkPowerState(adapter, callbackContext, new Runnable() {
        @Override/*from  w w w . jav  a2 s.co  m*/
        public void run() {
            try {
                // Each device connection has a GattHandler, which handles the events the can happen to the connection.
                // The implementation of the GattHandler class is found at the end of this file.
                GattHandler gh = new GattHandler(mNextGattHandle, callbackContext);
                gh.mGatt = adapter.getRemoteDevice(args.getString(0)).connectGatt(mContext, true, gh);
                // Note that gh.mGatt and this.mGatt are different object and have different types.
                if (mGatt == null)
                    mGatt = new HashMap<Integer, GattHandler>();
                Object res = mGatt.put(mNextGattHandle, gh);
                assert (res == null);
                mNextGattHandle++;
            } catch (Exception e) {
                e.printStackTrace();
                callbackContext.error(e.toString());
            }
        }
    });
}