From 7861641506c18255c571dea9fc62b2e35403caad Mon Sep 17 00:00:00 2001 From: TrillGates Date: Fri, 28 May 2021 20:34:17 +0800 Subject: [PATCH] add heart rate blood info to db. --- .../java/com/ic/work/SensorDataService.java | 64 +++++++++++++++++++ 1 file changed, 64 insertions(+) diff --git a/app/src/main/java/com/ic/work/SensorDataService.java b/app/src/main/java/com/ic/work/SensorDataService.java index 58bbd7a..32f7b34 100644 --- a/app/src/main/java/com/ic/work/SensorDataService.java +++ b/app/src/main/java/com/ic/work/SensorDataService.java @@ -1,7 +1,9 @@ package com.ic.work; import android.app.Service; +import android.content.ContentValues; import android.content.Intent; +import android.net.Uri; import android.os.IBinder; import android.os.PowerManager; import android.os.RemoteCallbackList; @@ -139,6 +141,36 @@ public class SensorDataService extends Service implements TemperatureHelper.Temp jxTempMode = -1; } sendTempBroadcast(wristTemp, bodyTemp, envTemp); + //写到设置项里,供各个地方获取 + temperatureSave2Db(wristTemp, bodyTemp, envTemp); + } + + public static final String PATH = "settings"; + public static final String AUTHORITY = "com.ic.fzd.settings"; + public static final String SETTINGS = "content://" + AUTHORITY + "/" + PATH; + + private void temperatureSave2Db(double wristTemp, double bodyTemp, double envTemp) { + ContentValues bodyTempValue = new ContentValues(); + bodyTempValue.put("s_key", "body_temperature"); + bodyTempValue.put("s_value", bodyTemp); + getContentResolver().insert( + Uri.parse(SETTINGS), + bodyTempValue + ); + ContentValues wristTempValue = new ContentValues(); + wristTempValue.put("s_key", "wrist_temperature"); + wristTempValue.put("s_value", wristTemp); + getContentResolver().insert( + Uri.parse(SETTINGS), + wristTempValue + ); + ContentValues evnTempValue = new ContentValues(); + evnTempValue.put("s_key", "env_temperature"); + evnTempValue.put("s_value", envTemp); + getContentResolver().insert( + Uri.parse(SETTINGS), + evnTempValue + ); } /** @@ -668,6 +700,38 @@ public class SensorDataService extends Service implements TemperatureHelper.Temp IcLog.d(TAG, "on blood test end..."); //checkContinue(); // 心率有一个方去结束 + //保存到数据库中 + heartRateSave2Db(high, low, heart, oxygen); + } + + /** + * 保存到数据库中,需要的地方监听即可,比如说Launcher + * + * @param high + * @param low + * @param heart + * @param oxygen + */ + private void heartRateSave2Db(int high, int low, int heart, int oxygen) { + ContentValues highValues = new ContentValues(); + highValues.put("s_key", "blood_high"); + highValues.put("s_value", high); + getContentResolver().insert(Uri.parse(SETTINGS), highValues); + + ContentValues lowValues = new ContentValues(); + lowValues.put("s_key", "blood_low"); + lowValues.put("s_value", low); + getContentResolver().insert(Uri.parse(SETTINGS), lowValues); + + ContentValues heartRateValues = new ContentValues(); + heartRateValues.put("s_key", "heart_rate"); + heartRateValues.put("s_value", heart); + getContentResolver().insert(Uri.parse(SETTINGS), heartRateValues); + + ContentValues oxygenValues = new ContentValues(); + oxygenValues.put("s_key", "oxygen"); + oxygenValues.put("s_value", oxygen); + getContentResolver().insert(Uri.parse(SETTINGS), oxygenValues); } @Override -- 2.17.1