简体   繁体   中英

Android listener (Read Mi band sensor data)

I want to get real sensor(accel) data from mi band.

I found good source code from github. But there was a problem.

https://github.com/pangliang/miband-sdk-android

MainActivity.java

else if (position == menuIndex++) {
                    Log.d(TAG, "setRealtimeStep");
                    miband.setRealtimeStepsNotifyListener(new RealtimeStepsNotifyListener() {
                        @Override
                        public void onNotify(int steps) {
                            Log.d(TAG, "RealtimeStepsNotifyListener:" + steps);
                        }
                    });

Miband.java

public void setSensorDataNotifyListener(final NotifyListener listener) {
    Log.d(TAG, "MiBand.java->setSensorDataNotifyListener");
    this.io.setNotifyListener(Profile.UUID_SERVICE_MILI, Profile.UUID_CHAR_SENSOR_DATA, new NotifyListener() {

        @Override
        public void onNotify(byte[] data) {
            Log.d(TAG, "MiBand.java->setSensorDataNotifyListener->onNotify");
            Log.d(TAG, data.toString());
            listener.onNotify(data);
        }
    });
}

BluetoothIO.java

public void setNotifyListener(UUID serviceUUID, UUID characteristicId, NotifyListener listener) {
    if (null == gatt) {
        Log.e(TAG, "connect to miband first");
        return;
    }

    BluetoothGattCharacteristic chara = gatt.getService(serviceUUID).getCharacteristic(characteristicId);
    if (chara == null) {
        Log.e(TAG, "characteristicId " + characteristicId.toString() + " not found in service " + serviceUUID.toString());
        return;
    }


    this.gatt.setCharacteristicNotification(chara, true);
    BluetoothGattDescriptor descriptor = chara.getDescriptor(Profile.UUID_DESCRIPTOR_UPDATE_NOTIFICATION);
    descriptor.setValue(BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE);
    this.gatt.writeDescriptor(descriptor);
    this.notifyListeners.put(characteristicId, listener);

In this code, I don't know which line can get sensor data. I don't know where should I add in 'OnNotify(data)'

If you have any clue, please help me. Thank you!

您必须在您的onDescriptorWrite回调中调用onNotify ,您onDescriptorWrite在其中验证描述符的 UUID 及其特征的 UUID 也请参阅

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM