Example usage for android.bluetooth BluetoothGatt requestMtu

List of usage examples for android.bluetooth BluetoothGatt requestMtu

Introduction

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

Prototype

public boolean requestMtu(int mtu) 

Source Link

Document

Request an MTU size used for a given connection.

Usage

From source file:org.physical_web.physicalweb.BluetoothSite.java

@Override
public void onConnectionStateChange(BluetoothGatt gatt, int status, int newState) {
    if (newState == BluetoothProfile.STATE_CONNECTED && status == gatt.GATT_SUCCESS) {
        Log.i(TAG, "Connected to GATT server");
        mBluetoothGatt = gatt;// w  w  w  . j  a  va 2  s .c o m
        if (VERSION.SDK_INT >= VERSION_CODES.LOLLIPOP) {
            gatt.requestConnectionPriority(CONNECTION_PRIORITY_HIGH);
            gatt.requestMtu(505);
        } else {
            gatt.discoverServices();
        }
    } else if (newState == BluetoothProfile.STATE_DISCONNECTED) {
        Log.i(TAG, "Disconnected to GATT server");
        // ensure progress dialog is removed and running is set false
        close();
    } else if (status != gatt.GATT_SUCCESS) {
        Log.i(TAG, "Status is " + status);
        close();
    }
}

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

@TargetApi(21)
public void setMtu(String address, int mtu) {
    BluetoothGatt bluetoothGatt = addressToGattClient.get(address);
    if (bluetoothGatt == null) {
        Log.w(TAG, "No connection found for: " + address);
        sendGattBroadcast(address, BleEvents.MTU_CHANGE_FAIL, null);
        return;// ww  w .j  a  v  a 2 s  .c  om
    }
    bluetoothGatt.requestMtu(mtu);
}