我正在开发一个使用BLE从另一个设备获取数据的Android应用程序。 我跟着Google Project Samples
我添加了一个菜单项,当我按下它时,我在设备中设置了date_time,并在设备上启用了指示,这样我就可以获得数据。
我现在正在尝试自动获取数据而不点击该按钮。设置了Date_time并在设备上启用了指示值,但我无法获取数据。
这是我点击菜单项时的代码:
case R.id.hMeasurement:
writeCharacteristicValue(searchSpecificCharacteristic(SampleGattAttributes.DATE_TIME),initDate());
getHeartRateMeasurement(searchSpecificCharacteristic(SampleGattAttributes.HEART_RATE_MEASUREMENT));
return true;
好吧我试着把这段代码放到后面我得到了所有的特征
private final BroadcastReceiver mGattUpdateReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
final String action = intent.getAction();
if (BluetoothLeService.ACTION_GATT_CONNECTED.equals(action)) {
mConnected = true;
updateConnectionState(R.string.connected);
invalidateOptionsMenu();
} else if (BluetoothLeService.ACTION_GATT_DISCONNECTED.equals(action)) {
mConnected = false;
updateConnectionState(R.string.disconnected);
invalidateOptionsMenu();
clearUI();
} else if (BluetoothLeService.ACTION_GATT_SERVICES_DISCOVERED.equals(action)) {
// Show all the supported services and characteristics on the user interface.
displayGattServices(mBluetoothLeService.getSupportedGattServices());
writeCharacteristicValue(searchSpecificCharacteristic(SampleGattAttributes.DATE_TIME),initDate());
getHeartRateMeasurement(searchSpecificCharacteristic(SampleGattAttributes.HEART_RATE_MEASUREMENT));
} else if (BluetoothLeService.ACTION_DATA_AVAILABLE.equals(action)) {
displayData((HashMap<String, String>) intent.getSerializableExtra(BluetoothLeService.EXTRA_DATA));
}
}
};
正如我所说,date_time已设置,指示已启用,但我可以获取数据,但我可以在5.0.1安卓设备上获取它。