Example usage for android.bluetooth.le AdvertiseSettings ADVERTISE_MODE_LOW_LATENCY

List of usage examples for android.bluetooth.le AdvertiseSettings ADVERTISE_MODE_LOW_LATENCY

Introduction

In this page you can find the example usage for android.bluetooth.le AdvertiseSettings ADVERTISE_MODE_LOW_LATENCY.

Prototype

int ADVERTISE_MODE_LOW_LATENCY

To view the source code for android.bluetooth.le AdvertiseSettings ADVERTISE_MODE_LOW_LATENCY.

Click Source Link

Document

Perform Bluetooth LE advertising in low latency, high power mode.

Usage

From source file:io.v.android.libs.discovery.ble.BlePlugin.java

private void readvertise() {
    if (advertiseCallback != null) {
        bluetoothLeAdvertise.stopAdvertising(advertiseCallback);
        advertiseCallback = null;// w ww .  j a va  2s . c  o m
    }
    if (advertisements.size() == 0) {
        return;
    }

    int hash = advertisements.hashCode();

    AdvertiseData.Builder builder = new AdvertiseData.Builder();
    ByteBuffer buf = ByteBuffer.allocate(9);
    buf.put((byte) 8);
    buf.putLong(hash);
    builder.addManufacturerData(1001, buf.array());
    AdvertiseSettings.Builder settingsBuilder = new AdvertiseSettings.Builder();
    settingsBuilder.setAdvertiseMode(AdvertiseSettings.ADVERTISE_MODE_LOW_LATENCY);
    settingsBuilder.setConnectable(true);
    advertiseCallback = new AdvertiseCallback() {
        @Override
        public void onStartSuccess(AdvertiseSettings settingsInEffect) {
            Log.i("vanadium", "Successfully started " + settingsInEffect);
        }

        @Override
        public void onStartFailure(int errorCode) {
            Log.i("vanadium", "Failed to start advertising " + errorCode);
        }
    };
    bluetoothLeAdvertise.startAdvertising(settingsBuilder.build(), builder.build(), advertiseCallback);
}