|
@@ -13,6 +13,10 @@ import android.content.Context;
|
|
|
import android.content.Intent;
|
|
|
import android.content.IntentFilter;
|
|
|
import android.content.ServiceConnection;
|
|
|
+import android.hardware.Sensor;
|
|
|
+import android.hardware.SensorEvent;
|
|
|
+import android.hardware.SensorEventListener;
|
|
|
+import android.hardware.SensorManager;
|
|
|
import android.location.Location;
|
|
|
import android.location.LocationManager;
|
|
|
import android.os.Binder;
|
|
@@ -44,33 +48,6 @@ import java.util.Locale;
|
|
|
import java.util.concurrent.ScheduledThreadPoolExecutor;
|
|
|
import java.util.concurrent.TimeUnit;
|
|
|
|
|
|
-import retrofit2.http.POST;
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
public class ReportService extends Service {
|
|
|
|
|
|
|
|
@@ -80,6 +57,11 @@ public class ReportService extends Service {
|
|
|
private String pathLog = "/jyClient/log/";
|
|
|
|
|
|
|
|
|
+ * 血压、心跳等数据写入成功
|
|
|
+ */
|
|
|
+ public static final int MSG_CODE_HTTP_IS_SUCCESS = 1001;
|
|
|
+
|
|
|
+
|
|
|
* binder实例
|
|
|
*/
|
|
|
private RestBinder restBinder = null;
|
|
@@ -110,39 +92,35 @@ public class ReportService extends Service {
|
|
|
*/
|
|
|
private ScheduledThreadPoolExecutor executor;
|
|
|
|
|
|
+ private int mStepDetector = 0;
|
|
|
+ private SensorManager mSensorManager;
|
|
|
+ private MySensorEventListener mListener;
|
|
|
|
|
|
@Override
|
|
|
public void onCreate() {
|
|
|
|
|
|
super.onCreate();
|
|
|
initLocationManager();
|
|
|
-
|
|
|
|
|
|
executor = new ScheduledThreadPoolExecutor(1);
|
|
|
executor.scheduleAtFixedRate(() -> {
|
|
|
startForeground(NOTICE_ID, new Notification());
|
|
|
-
|
|
|
+ ReportData report = new ReportData();
|
|
|
if (locationManager != null && locationProvider != null && locationProvider != "") {
|
|
|
@SuppressLint("MissingPermission")
|
|
|
Location location = locationManager.getLastKnownLocation(locationProvider);
|
|
|
|
|
|
if (location != null) {
|
|
|
- reportData.setLat(location.getLatitude() + "");
|
|
|
- reportData.setLng(location.getLongitude() + "");
|
|
|
+ report.setLat(location.getLatitude() + "");
|
|
|
+ report.setLng(location.getLongitude() + "");
|
|
|
}
|
|
|
+ report.setBs(mStepDetector + "");
|
|
|
}
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- GPSPost();
|
|
|
+ GPSPost(report);
|
|
|
}, 0, 5, TimeUnit.SECONDS);
|
|
|
+ executor.scheduleAtFixedRate(() -> {
|
|
|
+ Post();
|
|
|
+ }, 0, 10, TimeUnit.SECONDS);
|
|
|
startAlarmService();
|
|
|
}
|
|
|
|
|
@@ -156,10 +134,12 @@ public class ReportService extends Service {
|
|
|
|
|
|
if (alarmManager != null)
|
|
|
alarmManager.cancel(pendingIntent);
|
|
|
+
|
|
|
+ mSensorManager.unregisterListener(mListener);
|
|
|
}
|
|
|
|
|
|
|
|
|
- * 初始化GPS定位服务
|
|
|
+ * 初始化GPS定位服务和计步器服务
|
|
|
*/
|
|
|
private void initLocationManager() {
|
|
|
try {
|
|
@@ -178,20 +158,45 @@ public class ReportService extends Service {
|
|
|
} catch (Exception ex) {
|
|
|
System.out.println(ex.getMessage());
|
|
|
}
|
|
|
+
|
|
|
+ mSensorManager = (SensorManager) getSystemService(Context.SENSOR_SERVICE);
|
|
|
+ mListener = new MySensorEventListener();
|
|
|
+ mSensorManager.registerListener(mListener, mSensorManager.getDefaultSensor(Sensor.TYPE_STEP_DETECTOR),
|
|
|
+ SensorManager.SENSOR_DELAY_NORMAL);
|
|
|
+ mSensorManager.registerListener(mListener, mSensorManager.getDefaultSensor(Sensor.TYPE_STEP_COUNTER),
|
|
|
+ SensorManager.SENSOR_DELAY_NORMAL);
|
|
|
}
|
|
|
|
|
|
+ Handler handler = new Handler(new Handler.Callback() {
|
|
|
+ @Override
|
|
|
+ public boolean handleMessage(Message msg) {
|
|
|
+ if (msg.what == MSG_CODE_HTTP_IS_SUCCESS){
|
|
|
+ if (restBinder != null){
|
|
|
+ Log.e("=========", "回调关闭");
|
|
|
+ restBinder.callRemoteOpenBlood(false);
|
|
|
+ reportData.setPld(null);
|
|
|
+ reportData.setSsxy(null);
|
|
|
+ reportData.setSzxy(null);
|
|
|
+ reportData.setXtpl(null);
|
|
|
+ reportData.setXynd(null);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
|
|
|
* 采集手环数据
|
|
|
*/
|
|
|
- public static void Post() {
|
|
|
- RestService.Post(reportData);
|
|
|
+ public void Post() {
|
|
|
+ RestService.Post(reportData, handler);
|
|
|
}
|
|
|
|
|
|
|
|
|
* 采集手机数据
|
|
|
*/
|
|
|
- public static void GPSPost() {
|
|
|
- RestService.GPSPost(reportData);
|
|
|
+ public void GPSPost(ReportData report) {
|
|
|
+ RestService.GPSPost(report);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
@@ -458,10 +463,9 @@ public class ReportService extends Service {
|
|
|
|
|
|
public void callRemoteOpenBlood(boolean enable) {
|
|
|
Log.i(TAG, "callRemoteGetMutipleData");
|
|
|
- int result;
|
|
|
if (mService != null) {
|
|
|
try {
|
|
|
- result = mService.setBloodPressureMode(enable);
|
|
|
+ mService.setBloodPressureMode(enable);
|
|
|
} catch (RemoteException e) {
|
|
|
e.printStackTrace();
|
|
|
shotToast("Remote call error!");
|
|
@@ -750,7 +754,6 @@ public class ReportService extends Service {
|
|
|
|
|
|
@Override
|
|
|
public void onReceiveSensorData(int arg0, int arg1, int arg2, int arg3, int arg4) throws RemoteException {
|
|
|
-
|
|
|
Log.e("=========", "result:" + arg0 + " , " + arg1 + " , " + arg2 + " , " + arg3 + " , " + arg4);
|
|
|
|
|
|
if (arg0 > 0 && arg1 > 0 && arg2 > 0 && arg3 > 0 && arg4 > 0){
|
|
@@ -759,12 +762,6 @@ public class ReportService extends Service {
|
|
|
reportData.setSsxy(arg2 + "");
|
|
|
reportData.setXynd(arg3 + "");
|
|
|
reportData.setPld(arg4 + "");
|
|
|
-
|
|
|
- Post();
|
|
|
- if (restBinder != null){
|
|
|
- Log.e("=========", "回调关闭");
|
|
|
- restBinder.callRemoteOpenBlood(false);
|
|
|
- }
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -916,4 +913,21 @@ public class ReportService extends Service {
|
|
|
toast.show();
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+
|
|
|
+ class MySensorEventListener implements SensorEventListener {
|
|
|
+ @Override
|
|
|
+ public void onSensorChanged(SensorEvent event) {
|
|
|
+ if (event.sensor.getType() == Sensor.TYPE_STEP_DETECTOR) {
|
|
|
+ if (event.values[0] == 1.0f) {
|
|
|
+ mStepDetector++;
|
|
|
+ Log.i("==========步数读取: ", mStepDetector + "");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onAccuracyChanged(Sensor sensor, int accuracy) {
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|