From d78e3ed53b4ed431f0eb052a11e9b65feb5d2fbd Mon Sep 17 00:00:00 2001 From: sim Date: Mon, 11 Nov 2024 16:11:42 +0000 Subject: [PATCH 1/2] Request to ignore battery optimizations before receiving subscription This privilege is required to start a foreground service from the background. Which is what is intented to be done when the first registration is received with UnifiedPush --- app/src/main/java/io/heckel/ntfy/ui/MainActivity.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/java/io/heckel/ntfy/ui/MainActivity.kt b/app/src/main/java/io/heckel/ntfy/ui/MainActivity.kt index e131f32c..2f9bc897 100644 --- a/app/src/main/java/io/heckel/ntfy/ui/MainActivity.kt +++ b/app/src/main/java/io/heckel/ntfy/ui/MainActivity.kt @@ -233,7 +233,7 @@ class MainActivity : AppCompatActivity(), ActionMode.Callback, AddFragment.Subsc val hasInstantSubscriptions = subscriptions.count { it.instant } > 0 val batteryRemindTimeReached = repository.getBatteryOptimizationsRemindTime() < System.currentTimeMillis() val ignoringOptimizations = isIgnoringBatteryOptimizations(this@MainActivity) - val showBanner = hasInstantSubscriptions && batteryRemindTimeReached && !ignoringOptimizations + val showBanner = batteryRemindTimeReached && !ignoringOptimizations val batteryBanner = findViewById(R.id.main_banner_battery) batteryBanner.visibility = if (showBanner) View.VISIBLE else View.GONE Log.d(TAG, "Battery: ignoring optimizations = $ignoringOptimizations (we want this to be true); instant subscriptions = $hasInstantSubscriptions; remind time reached = $batteryRemindTimeReached; banner = $showBanner") From d08d227622493f77ecc19bb0294c8503929c9236 Mon Sep 17 00:00:00 2001 From: sim Date: Mon, 11 Nov 2024 17:09:11 +0000 Subject: [PATCH 2/2] Ignore battery optimizations without going to settings --- app/src/main/AndroidManifest.xml | 1 + .../java/io/heckel/ntfy/ui/MainActivity.kt | 21 +++++++++++++++++-- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 0950b404..f4425a16 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -11,6 +11,7 @@ +