Example usage for android.bluetooth BluetoothProfile STATE_DISCONNECTING

List of usage examples for android.bluetooth BluetoothProfile STATE_DISCONNECTING

Introduction

In this page you can find the example usage for android.bluetooth BluetoothProfile STATE_DISCONNECTING.

Prototype

int STATE_DISCONNECTING

To view the source code for android.bluetooth BluetoothProfile STATE_DISCONNECTING.

Click Source Link

Document

The profile is in disconnecting state

Usage

From source file:Main.java

public static String getBleConnectStatus(int status) {
    switch (status) {
    case BluetoothProfile.STATE_DISCONNECTED:
        return "STATE_DISCONNECTED";

    case BluetoothProfile.STATE_CONNECTING:
        return "STATE_CONNECTING";

    case BluetoothProfile.STATE_CONNECTED:
        return "STATE_CONNECTED";

    case BluetoothProfile.STATE_DISCONNECTING:
        return "STATE_DISCONNECTING";

    default://  w w w  . j a  v a2 s . c o  m
        return "STATE_UNKNOWN: " + status;
    }
}

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

private void setBleServiceListener() {
    mBleService.setOnConnectListener(new MultipleBleService.OnConnectionStateChangeListener() {
        @Override/*  www  .  j  a va  2s .  co m*/
        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) {

        }
    });
}

From source file:com.beestar.ble.ble.ui.MultipleBleActivity.java

private void setBleServiceListener() {
    mBleService.setOnConnectListener(new MultipleBleService.OnConnectionStateChangeListener() {
        @Override/*  w  w  w.  jav  a2 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.setOnServicesDiscoveredListener(new MultipleBleService.OnServicesDiscoveredListener() {
        @Override
        public void onServicesDiscovered(BluetoothGatt gatt, int status) {

            String characteristics_uuid_read = null;
            String characteristics_uuid_write = null;
            String read_Uuid = null;
            String write_Uuid = null;
            BluetoothGattCharacteristic characteristic;
            if (status == gatt.GATT_SUCCESS) {
                String address = gatt.getDevice().getAddress();
                List<BluetoothGattService> services = gatt.getServices();
                commonUtils = new CommonUtils(getApplicationContext());
                int j, k;
                for (int i = 0; i < services.size(); i++) {

                    if (services.get(i).getUuid().toString().contains("ffe5")) {
                        write_Uuid = services.get(i).getUuid().toString();
                        Log.i("info", "--------------------" + i);

                        characteristics_uuid_write = services.get(i).getCharacteristics().get(0).getUuid()
                                .toString();

                    }
                    if (services.get(i).getUuid().toString().contains("ffe0")) {
                        Log.i("info", "--------------------" + i);
                        characteristic = services.get(i).getCharacteristic(services.get(i).getUuid());
                        read_Uuid = services.get(i).getUuid().toString();
                        characteristics_uuid_read = services.get(i).getCharacteristics().get(0).getUuid()
                                .toString();

                    }
                }
                Equipment_Device equipment_device = new Equipment_Device();
                equipment_device.setAddress(address);
                equipment_device.setRead_uuid(read_Uuid);
                equipment_device.setRead_uuid(write_Uuid);
                equipment_device.setCh_read_uuid(characteristics_uuid_read);
                equipment_device.setCh_write_uuid(characteristics_uuid_write);
                commonUtils.insertStudent(equipment_device);
            }
        }
    });
    mBleService.setOnConnectListener(new MultipleBleService.OnConnectionStateChangeListener() {
        @Override
        public void onConnectionStateChange(BluetoothGatt gatt, int status, int newState) {

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

        }
    });
}

From source file:com.google.android.apps.forscience.ble.MyBleService.java

public void disconnectDevice(String address) {
    BluetoothGatt bluetoothGatt = addressToGattClient.get(address);
    if (btAdapter == null || address == null || bluetoothGatt == null) {
        return;// ww  w  .j  a v a  2  s.co m
    }
    BluetoothDevice device = btAdapter.getRemoteDevice(address);
    int bleState = bluetoothManager.getConnectionState(device, BluetoothProfile.GATT);
    if (bleState != BluetoothProfile.STATE_DISCONNECTED && bleState != BluetoothProfile.STATE_DISCONNECTING) {
        bluetoothGatt.disconnect();
    } else {
        bluetoothGatt.close();
        addressToGattClient.remove(address);
        sendGattBroadcast(address, BleEvents.GATT_DISCONNECT, null);
    }
}