From 3998d142231cd1aac06091b3a2abc3dc9477ce16 Mon Sep 17 00:00:00 2001 From: Matthew Date: Fri, 27 Sep 2024 18:37:55 +0800 Subject: [PATCH] =?UTF-8?q?GPS=E7=8A=B6=E6=80=81=E7=9A=84=E8=87=AA?= =?UTF-8?q?=E5=8A=A8=E7=9B=91=E6=B5=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 超过10分钟,自动关闭 --- .../java/com/xypower/mpapp/MicroPhotoService.java | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/app/src/main/java/com/xypower/mpapp/MicroPhotoService.java b/app/src/main/java/com/xypower/mpapp/MicroPhotoService.java index 5a9f9ea0..7554cbb1 100644 --- a/app/src/main/java/com/xypower/mpapp/MicroPhotoService.java +++ b/app/src/main/java/com/xypower/mpapp/MicroPhotoService.java @@ -137,6 +137,7 @@ public class MicroPhotoService extends Service { private long mGpsTimeout = 60000; // 1 minute private PendingIntent mPreviousGpsTimer = null; + private long mLastLocationRequested = 0; private ServiceHandler mHander = null; private Messenger mMessenger = null; @@ -318,6 +319,9 @@ public class MicroPhotoService extends Service { mService.registerHeartbeatTimer(mService.mHeartbeatDuration); try { + + mService.detectGpsStatus(); + ConnectivityManager connectivityManager = (ConnectivityManager)context.getSystemService(Context.CONNECTIVITY_SERVICE); if (connectivityManager != null) { if (!connectivityManager.isDefaultNetworkActive()) { @@ -1072,6 +1076,8 @@ public class MicroPhotoService extends Service { // Set Listener } try { + enableGps(true); + mLastLocationRequested = System.currentTimeMillis(); mLocationManager.requestLocationUpdates(mLocateType, 30000, 1, mLocationListener, Looper.getMainLooper()); } catch (Exception ex) { ex.printStackTrace(); @@ -1090,6 +1096,13 @@ public class MicroPhotoService extends Service { return false; } + private void detectGpsStatus() { + if (System.currentTimeMillis() - mLastLocationRequested > 10 * 60000) { + // 10minutes close it + enableGps(false); + } + } + public void downloadAndInstall(final String url) { final Context context = getApplicationContext();