From c0d2f57ec0bda5fcecebe6d17c9acf8f87ae92b5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B8=96=E7=95=8C?= Date: Mon, 11 Dec 2023 18:59:40 +0800 Subject: [PATCH] Fix start loop on MIUI --- app/src/main/java/io/nekohasekai/sfa/ui/MainActivity.kt | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/io/nekohasekai/sfa/ui/MainActivity.kt b/app/src/main/java/io/nekohasekai/sfa/ui/MainActivity.kt index fe222b3..529ad23 100644 --- a/app/src/main/java/io/nekohasekai/sfa/ui/MainActivity.kt +++ b/app/src/main/java/io/nekohasekai/sfa/ui/MainActivity.kt @@ -184,13 +184,14 @@ class MainActivity : AbstractActivity(), ServiceConnection.Callback { } @SuppressLint("NewApi") - fun startService() { + fun startService(skipRequestFineLocation: Boolean = false) { if (!ServiceNotification.checkPermission()) { notificationPermissionLauncher.launch(Manifest.permission.POST_NOTIFICATIONS) return } - if (ContextCompat.checkSelfPermission( + // MIUI always return false for shouldShowRequestPermissionRationale + if (!skipRequestFineLocation && ContextCompat.checkSelfPermission( this, Manifest.permission.ACCESS_FINE_LOCATION ) != PackageManager.PERMISSION_GRANTED ) { @@ -204,7 +205,6 @@ class MainActivity : AbstractActivity(), ServiceConnection.Callback { } } - lifecycleScope.launch(Dispatchers.IO) { if (Settings.rebuildServiceMode()) { reconnect() @@ -234,7 +234,7 @@ class MainActivity : AbstractActivity(), ServiceConnection.Callback { private val fineLocationPermissionLauncher = registerForActivityResult( ActivityResultContracts.RequestPermission() ) { - startService() + startService(true) } private val prepareLauncher = registerForActivityResult(PrepareService()) {