Example usage for android.bluetooth BluetoothGatt getDevice

List of usage examples for android.bluetooth BluetoothGatt getDevice

Introduction

In this page you can find the example usage for android.bluetooth BluetoothGatt getDevice.

Prototype

public BluetoothDevice getDevice() 

Source Link

Document

Return the remote bluetooth device this GATT client targets to

Usage

From source file:Main.java

public static String formatGattShort(BluetoothGatt gatt) {
    BluetoothDevice device = gatt.getDevice();
    String log = "";
    if (device != null)
        log += device.getName();// ww w  .  j  a  v  a  2  s .  com
    else
        log += "unknown";

    return log;
}

From source file:Main.java

public static String gattToString(BluetoothGatt gatt) {
    if (gatt == null) {
        return "null";
    }//from w w w .  j a v  a  2  s  . c  o m
    return "gatt:" + gatt.getDevice().getName();
}

From source file:ble.AndroidBle.java

@Override
public boolean requestWriteCharacteristic(String address, BleGattCharacteristic characteristic, String remark) {
    BluetoothGatt gatt = mBluetoothGatts.get(address);
    if (gatt == null || characteristic == null) {
        return false;
    }//from w w  w .  j  a  v  a 2  s .  c  o m

    mService.addBleRequest(new BleRequest(RequestType.WRITE_CHARACTERISTIC, gatt.getDevice().getAddress(),
            characteristic, remark));
    return true;
}

From source file:ble.AndroidBle.java

@Override
public boolean requestIndication(String address, BleGattCharacteristic characteristic) {
    BluetoothGatt gatt = mBluetoothGatts.get(address);
    if (gatt == null || characteristic == null) {
        return false;
    }/*from  ww  w . j a v  a  2s .c  o m*/

    mService.addBleRequest(new BleRequest(RequestType.CHARACTERISTIC_INDICATION, gatt.getDevice().getAddress(),
            characteristic));
    return true;
}

From source file:ble.AndroidBle.java

@Override
public boolean requestReadCharacteristic(String address, BleGattCharacteristic characteristic) {
    BluetoothGatt gatt = mBluetoothGatts.get(address);
    if (gatt == null || characteristic == null) {
        return false;
    }/*from w ww.  j  av  a 2 s  .co m*/

    mService.addBleRequest(
            new BleRequest(RequestType.READ_CHARACTERISTIC, gatt.getDevice().getAddress(), characteristic));
    return true;
}

From source file:ble.AndroidBle.java

@Override
public boolean requestCharacteristicNotification(String address, BleGattCharacteristic characteristic) {
    BluetoothGatt gatt = mBluetoothGatts.get(address);
    if (gatt == null || characteristic == null) {
        return false;
    }/*from www. jav  a2s  .  c  o m*/

    mService.addBleRequest(new BleRequest(RequestType.CHARACTERISTIC_NOTIFICATION,
            gatt.getDevice().getAddress(), characteristic));
    return true;
}

From source file:ble.AndroidBle.java

@Override
public boolean requestStopNotification(String address, BleGattCharacteristic characteristic) {
    BluetoothGatt gatt = mBluetoothGatts.get(address);
    if (gatt == null || characteristic == null) {
        return false;
    }//from ww  w  . ja  v a 2  s.c o m

    mService.addBleRequest(new BleRequest(RequestType.CHARACTERISTIC_NOTIFICATION,
            gatt.getDevice().getAddress(), characteristic));
    return true;
}

From source file:kr.ac.kaist.resl.sensorservice.BluetoothService.java

private boolean readCharacteristics(BluetoothGatt gatt) {
    if (null == gatt)
        return false;

    String deviceName = gatt.getDevice().getName();
    List<BluetoothGattService> gattServices = gatt.getServices();

    if (gattServices == null)
        return false;

    String unknownServiceString = getResources().getString(R.string.unknown_service);
    String unknownCharaString = getResources().getString(R.string.unknown_characteristic);

    // Find the device node from device-service-characteristic tree
    Node<String> deviceNode = null;
    for (Node<String> node : device_service_characteristicTree.getChildren()) {
        if (node.data.equals(deviceName)) {
            deviceNode = node;//from   ww  w. ja  v  a 2 s . c  om
            break;
        }
    }

    // Loops through available GATT Services.
    for (BluetoothGattService gattService : gattServices) {
        String serviceUuid = gattService.getUuid().toString();
        String serviceName = SampleGattAttributes.lookup(serviceUuid, unknownServiceString);

        // Find desired service
        for (Node<String> serviceNode : deviceNode.getChildren()) {
            if (serviceName.equals(serviceNode.data)) {
                List<BluetoothGattCharacteristic> gattCharacteristics = gattService.getCharacteristics();

                // Loops through available Characteristics.
                for (BluetoothGattCharacteristic gattCharacteristic : gattCharacteristics) {
                    String characteristicUuid = gattCharacteristic.getUuid().toString();
                    String characteristicName = SampleGattAttributes.lookup(characteristicUuid,
                            unknownCharaString);

                    // Find desired characteristic of selected service
                    for (Node<String> characteristicNode : serviceNode.getChildren()) {
                        if (characteristicName.equals(characteristicNode.data)) {
                            Log.i(null, "FOUND DESIRED characteristic!!!");
                            readCharacteristic(gatt, gattCharacteristic);
                            break;
                        }
                    }

                }
            }
        }
    }
    return true;

}

From source file:com.wolkabout.hexiwear.service.BluetoothService.java

private void handleAuthenticationError(final BluetoothGatt gatt) {
    gatt.close();/*from  w w w  .  j  a v  a2  s  .  c  o m*/
    sendBroadcast(new Intent(BluetoothService.ACTION_NEEDS_BOND));
    gatt.getDevice().createBond();
}

From source file:com.junkchen.blelib.sample.MultipleBleActivity.java

private void setBleServiceListener() {
    mBleService.setOnConnectListener(new MultipleBleService.OnConnectionStateChangeListener() {
        @Override//from  ww w.j a v  a  2 s  .com
        public void onConnectionStateChange(BluetoothGatt gatt, int status, int newState) {
            if (newState == BluetoothProfile.STATE_DISCONNECTED) {
                for (int i = 0; i < deviceList.size(); i++) {
                    HashMap<String, Object> devMap = (HashMap<String, Object>) deviceList.get(i);
                    if (devMap.get("address").toString().equals(gatt.getDevice().getAddress())) {
                        ((HashMap) deviceList.get(i)).put("isConnect", false);
                        return;
                    }
                }
            } else if (newState == BluetoothProfile.STATE_CONNECTING) {

            } else if (newState == BluetoothProfile.STATE_CONNECTED) {
                for (int i = 0; i < deviceList.size(); i++) {
                    HashMap<String, Object> devMap = (HashMap<String, Object>) deviceList.get(i);
                    if (devMap.get("address").toString().equals(gatt.getDevice().getAddress())) {
                        ((HashMap) deviceList.get(i)).put("isConnect", true);
                        return;
                    }
                }
            } else if (newState == BluetoothProfile.STATE_DISCONNECTING) {

            }
        }
    });
    mBleService.setOnDataAvailableListener(new MultipleBleService.OnDataAvailableListener() {
        @Override
        public void onCharacteristicRead(BluetoothGatt gatt, BluetoothGattCharacteristic characteristic,
                int status) {

        }

        @Override
        public void onCharacteristicChanged(BluetoothGatt gatt, BluetoothGattCharacteristic characteristic) {

        }

        @Override
        public void onDescriptorRead(BluetoothGatt gatt, BluetoothGattDescriptor descriptor, int status) {

        }
    });
}