|
@@ -21,6 +21,7 @@ import android.os.Handler;
|
|
|
import android.os.IBinder;
|
|
|
import android.os.Message;
|
|
|
import android.os.RemoteException;
|
|
|
+import android.text.TextUtils;
|
|
|
import android.util.Log;
|
|
|
import android.widget.Toast;
|
|
|
|
|
@@ -43,6 +44,8 @@ import java.util.Locale;
|
|
|
import java.util.concurrent.ScheduledThreadPoolExecutor;
|
|
|
import java.util.concurrent.TimeUnit;
|
|
|
|
|
|
+import retrofit2.http.POST;
|
|
|
+
|
|
|
|
|
|
//接口地址:
|
|
|
//
|
|
@@ -112,14 +115,34 @@ public class ReportService extends Service {
|
|
|
public void onCreate() {
|
|
|
//TODO 在单纯提高优先级时,服务在关闭APP并关屏的情况下走了30分钟
|
|
|
super.onCreate();
|
|
|
+ initLocationManager();
|
|
|
+
|
|
|
//TODO 起一个ScheduledThreadPoolExecutor线程池,无延迟、1分钟执行1次来提高service的优先级,未必好用,聊胜于无
|
|
|
executor = new ScheduledThreadPoolExecutor(1);
|
|
|
executor.scheduleAtFixedRate(() -> {
|
|
|
startForeground(NOTICE_ID, new Notification());
|
|
|
//TODO 提交改在这里
|
|
|
- Post();
|
|
|
- }, 0, 1, TimeUnit.MINUTES);
|
|
|
- initLocationManager();
|
|
|
+ if (locationManager != null && locationProvider != null && locationProvider != "") {
|
|
|
+ @SuppressLint("MissingPermission")
|
|
|
+ Location location = locationManager.getLastKnownLocation(locationProvider);
|
|
|
+
|
|
|
+ if (location != null) {
|
|
|
+ reportData.setLat(location.getLatitude() + "");
|
|
|
+ reportData.setLng(location.getLongitude() + "");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+// if (mService != null) {
|
|
|
+// try {
|
|
|
+// int step = mService.getCurSportData();
|
|
|
+// if (step > 0)
|
|
|
+// reportData.setBs(step + "");
|
|
|
+// } catch (RemoteException e) {
|
|
|
+// e.printStackTrace();
|
|
|
+// }
|
|
|
+// }
|
|
|
+ GPSPost();
|
|
|
+ }, 0, 5, TimeUnit.SECONDS);
|
|
|
startAlarmService();
|
|
|
}
|
|
|
|
|
@@ -157,38 +180,18 @@ public class ReportService extends Service {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 采集手环数据
|
|
|
+ */
|
|
|
public static void Post() {
|
|
|
-
|
|
|
RestService.Post(reportData);
|
|
|
+ }
|
|
|
|
|
|
-// String action = "/shbruser/insertBraceletUserInfo";
|
|
|
-// Log.e("测试", "服务还在");
|
|
|
-
|
|
|
-// Gson gson = new Gson();
|
|
|
-// //使用RXJAVA来实现的异步提交的监听,不要单独使用线程来做管理,最起码也得用线程池
|
|
|
-// new SimpleRequest().post(action, gson.toJson(reportData), new DefaultObserver<ResponseBody>() {
|
|
|
-// @Override
|
|
|
-// public void onNext(ResponseBody responseBody) {
|
|
|
-// try {
|
|
|
-// String resultJson = responseBody.string();
|
|
|
-// System.out.println("服务器返回值:" + resultJson);
|
|
|
-// } catch (IOException e) {
|
|
|
-// Log.e("SimpleRequest", "获取返回值失败");
|
|
|
-// e.printStackTrace();
|
|
|
-// }
|
|
|
-// }
|
|
|
-//
|
|
|
-// @Override
|
|
|
-// public void onError(Throwable e) {
|
|
|
-// Log.e("SimpleRequest", "请求失败");
|
|
|
-// e.printStackTrace();
|
|
|
-// }
|
|
|
-//
|
|
|
-// @Override
|
|
|
-// public void onComplete() {
|
|
|
-// Log.e("SimpleRequest", "请求完成");
|
|
|
-// }
|
|
|
-// });
|
|
|
+ /**
|
|
|
+ * 采集手机数据
|
|
|
+ */
|
|
|
+ public static void GPSPost() {
|
|
|
+ RestService.GPSPost(reportData);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
@@ -634,14 +637,13 @@ public class ReportService extends Service {
|
|
|
@Override
|
|
|
public void onGetCurSportData(int type, long timestamp, int step, int distance,
|
|
|
int cal, int cursleeptime, int totalrunningtime, int steptime) throws RemoteException {
|
|
|
- Date date = new Date(timestamp * 1000);
|
|
|
- SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.getDefault());
|
|
|
- String time = sdf.format(date);
|
|
|
- showToast("onGetCurSportData", "type : " + type + " , time :" + time + " , step: " + step + ", distance :" + distance + ", cal :" + cal + ", cursleeptime :" + cursleeptime + ", totalrunningtime:" + totalrunningtime);
|
|
|
-
|
|
|
- if (reportData != null && step > 0)
|
|
|
- reportData.setBs(step + "");
|
|
|
-
|
|
|
+// Date date = new Date(timestamp * 1000);
|
|
|
+// SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.getDefault());
|
|
|
+// String time = sdf.format(date);
|
|
|
+// showToast("onGetCurSportData", "type : " + type + " , time :" + time + " , step: " + step + ", distance :" + distance + ", cal :" + cal + ", cursleeptime :" + cursleeptime + ", totalrunningtime:" + totalrunningtime);
|
|
|
+// Log.i("========运动数据", "type : " + type + " , time :" + time + " , step: " + step + ", distance :" + distance + ", cal :" + cal + ", cursleeptime :" + cursleeptime + ", totalrunningtime:" + totalrunningtime);
|
|
|
+// if (reportData != null && step > 0)
|
|
|
+// reportData.setBs(step + "");
|
|
|
}
|
|
|
|
|
|
@Override
|
|
@@ -750,59 +752,18 @@ public class ReportService extends Service {
|
|
|
public void onReceiveSensorData(int arg0, int arg1, int arg2, int arg3, int arg4) throws RemoteException {
|
|
|
// showToast("======onReceiveSensorData", "result:" + arg0 + " , " + arg1 + " , " + arg2 + " , " + arg3 + " , " + arg4);
|
|
|
Log.e("=========", "result:" + arg0 + " , " + arg1 + " , " + arg2 + " , " + arg3 + " , " + arg4);
|
|
|
-
|
|
|
-// reportData.setPld("");
|
|
|
-// reportData.setSsxy("");
|
|
|
-// reportData.setSzxy("");
|
|
|
-// reportData.setXtpl("");
|
|
|
-// reportData.setXynd("");
|
|
|
-
|
|
|
- //当手环采集到有效心率血压血氧值后,会通过此命令返回数据给app
|
|
|
-// void onReceiveSensorData(int heartrate, int Systolicpressure, int Diastolicpressure, int Oxygen, int Fatiguevalue);
|
|
|
-// heartrate:心率,
|
|
|
-// Systolicpressure:血压,收缩压
|
|
|
-// Diastolicpressure:血压,舒张压
|
|
|
-// Oxygen:血氧
|
|
|
-// Fatiguevalue:疲劳值
|
|
|
-
|
|
|
- long ts = new Date().getTime();
|
|
|
- if (arg0 > 0) {
|
|
|
+ // 采集到数据后写入数据库且关闭测量
|
|
|
+ if (arg0 > 0 && arg1 > 0 && arg2 > 0 && arg3 > 0 && arg4 > 0){
|
|
|
reportData.setXtpl(arg0 + "");
|
|
|
- }
|
|
|
-
|
|
|
- if (arg1 > 0) {
|
|
|
reportData.setSzxy(arg1 + "");
|
|
|
- }
|
|
|
-
|
|
|
- if (arg2 > 0) {
|
|
|
reportData.setSsxy(arg2 + "");
|
|
|
- }
|
|
|
-
|
|
|
- if (arg3 > 0) {
|
|
|
reportData.setXynd(arg3 + "");
|
|
|
- }
|
|
|
-
|
|
|
- if (arg4 > 0) {
|
|
|
reportData.setPld(arg4 + "");
|
|
|
- }
|
|
|
-
|
|
|
- if (locationManager != null && locationProvider != null && locationProvider != "") {
|
|
|
- @SuppressLint("MissingPermission")
|
|
|
- Location location = locationManager.getLastKnownLocation(locationProvider);
|
|
|
|
|
|
- if (location != null) {
|
|
|
- reportData.setLat(location.getLatitude() + "");
|
|
|
- reportData.setLng(location.getLongitude() + "");
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- if (mService != null) {
|
|
|
- try {
|
|
|
- int step = mService.getCurSportData();
|
|
|
- if (step > 0)
|
|
|
- reportData.setBs(step + "");
|
|
|
- } catch (RemoteException e) {
|
|
|
- e.printStackTrace();
|
|
|
+ Post();
|
|
|
+ if (restBinder != null){
|
|
|
+ Log.e("=========", "回调关闭");
|
|
|
+ restBinder.callRemoteOpenBlood(false);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -884,7 +845,7 @@ public class ReportService extends Service {
|
|
|
Intent intent = new Intent();
|
|
|
intent.setAction("action.STARTEARTBEATTEST");
|
|
|
pendingIntent = PendingIntent.getBroadcast(this, 100, intent, PendingIntent.FLAG_CANCEL_CURRENT);
|
|
|
- alarmManager.setRepeating(AlarmManager.RTC_WAKEUP, 5000, 60000, pendingIntent);
|
|
|
+ alarmManager.setRepeating(AlarmManager.RTC_WAKEUP, 0, 5 * 60 * 1000, pendingIntent);
|
|
|
|
|
|
showToast("AlarmBroadcastReceiver", "报警服务start!!!!!");
|
|
|
|