我想从mi band获得真实的传感器(加速)数据。
我从github找到了很好的源代码。但是有一个问题。
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);
在此代码中,我不知道哪条线可以获取传感器数据。 我不知道我应该在哪里添加'OnNotify(数据)'
如果您有任何线索,请帮助我。 谢谢!