添加了GPS时间,如果当前设备的时间在2022年之前,就会使用GPS时间. l005_l004pt
authorTrillGates <WilliamTrillGates@gmail.com>
Fri, 18 Mar 2022 06:31:49 +0000 (14:31 +0800)
committerTrillGates <WilliamTrillGates@gmail.com>
Fri, 18 Mar 2022 06:31:49 +0000 (14:31 +0800)
app/src/main/java/com/enqualcomm/support/NMEAListener.java
app/src/main/java/com/enqualcomm/support/utils/TimeUtil.java

index 6c0afa1..bf38288 100644 (file)
@@ -202,6 +202,12 @@ public class NMEAListener implements NmeaListener, LocationListener {
             String Lat = tmplist[1];
             String lon = tmplist[3];
             String fixed = tmplist[6];
+            String utctime = tmplist[5];
+            try {
+                TimeUtil.sGpsTime = utctime.substring(0, 6);
+            } catch (Exception e) {
+                e.printStackTrace();
+            }
             //      ICLogger.i("GPGLL Lat="+Lat+",Lon="+lon+",fixed="+fixed);
 
         } else if (nmeastr.startsWith("$GPRMC,") || nmeastr.startsWith("$GNRMC,")) {
@@ -228,6 +234,13 @@ public class NMEAListener implements NmeaListener, LocationListener {
             String lon = tmplist[5];
             String fixed = tmplist[2];
             String speed = tmplist[7];
+            String date = tmplist[9];
+            try {
+                TimeUtil.sGpsTime = utctime.substring(0, 6);
+                TimeUtil.sGpsDate = date;
+            } catch (Exception e) {
+                e.printStackTrace();
+            }
             //      ICLogger.i("GPRMC GPSTime="+utctime+",Lat="+Lat+",Lon="+lon+",fixed="+fixed+",speed="+speed);
             //      if (Config.LOG_TOFILE)
             //        FileOutputUtil.fileOutput(this.runtime.getCacheDir(), "GPS", "GPRMC GPSTime="+utctime+",Lat="+Lat+",Lon="+lon+",fixed="+fixed+",speed="+speed);
@@ -348,7 +361,11 @@ public class NMEAListener implements NmeaListener, LocationListener {
             String fixed = tmplist[6];
             String usedStarts = tmplist[7];
             String hdop = tmplist[8];
-
+            try {
+                TimeUtil.sGpsTime = utctime.substring(0, 6);
+            } catch (Exception e) {
+                e.printStackTrace();
+            }
 
             if ((fixed.trim().equals("1")) || (fixed.trim().equals("2")) || (fixed.trim().equals("6"))) {
 
index ee41777..ded5168 100644 (file)
@@ -2,14 +2,12 @@ package com.enqualcomm.support.utils;
 
 import android.app.AlarmManager;
 import android.content.Context;
-import android.os.Handler;
 import android.provider.Settings;
 import android.text.format.DateFormat;
 import android.util.Log;
 
 import com.ic.iclooger.ICLogger;
 
-import java.sql.Time;
 import java.text.ParseException;
 import java.text.SimpleDateFormat;
 import java.util.Calendar;
@@ -91,15 +89,28 @@ public class TimeUtil {
         return (new SimpleDateFormat("HHmmss")).format(new Date(System.currentTimeMillis()));
     }
 
+    //这个是GPS的时间,修改位置在NMEAListener上
+    public static String sGpsDate = "220101";
+
     public static String getUTCSystemDateYYMMDD() {
         SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyMMdd");
         simpleDateFormat.setTimeZone(TimeZone.getTimeZone("GMT+00:00"));
+        //如果当前的时间是2022年以前的,那么就使用GPS的时间
+        if (System.currentTimeMillis() < 1640966400000L) {
+            return sGpsDate;
+        }
         return simpleDateFormat.format(new Date());
     }
 
+    //这个时间在NMEAListener里修改,GPS的时间
+    public static String sGpsTime = "000000";
+
     public static String getUTCSystemTimeHHmmss() {
         SimpleDateFormat simpleDateFormat = new SimpleDateFormat("HHmmss");
         simpleDateFormat.setTimeZone(TimeZone.getTimeZone("GMT+00:00"));
+        if (System.currentTimeMillis() < 1640966400000L) {
+            return sGpsTime;
+        }
         String format = simpleDateFormat.format(new Date());
         ICLogger.d("getUTCSystemTimeHHmmss ==>   " + format);
         return format;