From 8246400db7c1343ae02db329f4b2189c8f9580db Mon Sep 17 00:00:00 2001 From: liwei1dao Date: Sat, 20 Sep 2025 19:31:22 +0800 Subject: [PATCH] =?UTF-8?q?=E4=B8=8A=E4=BC=A0=E5=AE=9A=E4=BD=8D=E6=9D=83?= =?UTF-8?q?=E9=99=90=E6=A3=80=E6=B5=8B=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../location_service/LocationService.kt | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/local_plugins/location_service/android/src/main/kotlin/com/yunqiinnovation/location_service/LocationService.kt b/local_plugins/location_service/android/src/main/kotlin/com/yunqiinnovation/location_service/LocationService.kt index b85738b1f..5e051d418 100644 --- a/local_plugins/location_service/android/src/main/kotlin/com/yunqiinnovation/location_service/LocationService.kt +++ b/local_plugins/location_service/android/src/main/kotlin/com/yunqiinnovation/location_service/LocationService.kt @@ -270,13 +270,19 @@ object LocationService { if (!hasForegroundPermission) { return 1 // 前台权限未授予 } - + // 前台权限已授予,再根据前后台状态检查后台权限 if (!isAppInForeground(context)) { - // 应用在后台:Android 10+ 需要检查后台权限 - return 2 // 后台权限未授予 + // 应用在后台:Android 10+ 需要检查后台权限的实际授予状态 + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) { + val hasBackgroundPermission = hasBackgroundLocationPermission(context) + if (!hasBackgroundPermission) { + return 2 // 后台权限未授予 + } + } + // Android 9 及以下或已授予后台权限 } - + // 所有所需权限均已授予 return 0 }