We're making some changes to the Google Fit APIs. Learn about how these changes might affect your app. Read our new policy.

Use Bluetooth Sensors

Google Fit includes support for Bluetooth Low Energy sensors that implement a standard GATT profile. The Bluetooth Low Energy API enables your app to look for available BLE devices and to use a BLE device with the Recording API and the Sensors API.

Scan for available devices

To scan for nearby BLE devices, use the BleClient.startBleScan method:

BleScanCallback bleScanCallbacks = new BleScanCallback() {
    @Override
    public void onDeviceFound(BleDevice device) {
        // A device that provides the requested data types is available
    }
    @Override
    public void onScanStopped() {
        // The scan timed out or was interrupted
    }
};

Task<Void> response = Fitness
        .getBleClient(this, GoogleSignIn.getAccountForExtension(this, fitnessOptions))
        .startBleScan(
            Arrays.asList(DataType.TYPE_STEP_COUNT_DELTA), 1000, bleScanCallbacks);

Claim a device

To make a BLE device available to the Recording API and the Sensors API, use the BleClient.claimBleDevice method:

Task<Void> response = Fitness
        .getBleClient(this, GoogleSignIn.getAccountForExtension(this, fitnessOptions))
        .claimBleDevice(device);

If the BLE device is claimed successfully, you can access it like any other sensor using the Recording API and the Sensors API. For example, you can obtain a data source object for the BLE device with the SensorsClient.findDataSources method.

Release a device

To stop using a BLE device with Google Fit, use the BleClient.unclaimBleDevice method:

Task<Void> response = Fitness
        .getBleClient(this, GoogleSignIn.getAccountForExtension(this, fitnessOptions))
        .unclaimBleDevice(device);

If the request is successful, the BLE device no longer appears as an available sensor in Google Fit.