From 6eb097a033a397699c9cbf94db31787a343cd7e5 Mon Sep 17 00:00:00 2001 From: renwj Date: Wed, 19 Oct 2022 19:41:35 +0800 Subject: [PATCH] =?UTF-8?q?[=E7=8A=B6=E6=80=81=E6=A0=8F][GPS]=E4=BF=AE?= =?UTF-8?q?=E6=AD=A3=E5=BA=94=E7=94=A8=E9=A6=96=E6=AC=A1=E5=90=AF=E5=8A=A8?= =?UTF-8?q?=E5=90=8E=EF=BC=8C=E6=8E=88=E6=9D=83=E5=90=8E=EF=BC=8CGPS?= =?UTF-8?q?=E7=8A=B6=E6=80=81=E6=9C=AA=E9=AB=98=E4=BA=AE=E6=98=BE=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../status/flow/gps/GpsImpl.kt | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/core/function-impl/mogo-core-function-devatools/src/main/java/com/zhjt/mogo_core_function_devatools/status/flow/gps/GpsImpl.kt b/core/function-impl/mogo-core-function-devatools/src/main/java/com/zhjt/mogo_core_function_devatools/status/flow/gps/GpsImpl.kt index 01b5a2ff9f..43c94c86b5 100644 --- a/core/function-impl/mogo-core-function-devatools/src/main/java/com/zhjt/mogo_core_function_devatools/status/flow/gps/GpsImpl.kt +++ b/core/function-impl/mogo-core-function-devatools/src/main/java/com/zhjt/mogo_core_function_devatools/status/flow/gps/GpsImpl.kt @@ -49,9 +49,19 @@ internal class GpsImpl(ctx: Context): IFlow(ctx) { false } + private val onStateListener = object : IAppStateListener { + + override fun onAppStateChanged(isForeground: Boolean) { + if (isForeground) { + send(isLocationEnabled(), isGrandFineLocation()) + } + } + } + override fun onCreate() { val isGranted = isGrandFineLocation() + AppStateManager.registerAppStateListener(onStateListener) send(isLocationEnabled(), isGranted) if (!isGranted) { PermissionUtils.requestAccessFineLocation(object : SimpleCallback { @@ -88,6 +98,7 @@ internal class GpsImpl(ctx: Context): IFlow(ctx) { } catch (t: Throwable) { t.printStackTrace() } + AppStateManager.unRegisterAppStateListener(onStateListener) } } \ No newline at end of file