From d04c3a300567dd240b1deb2df99b151fe929e6ae Mon Sep 17 00:00:00 2001 From: M66B Date: Thu, 3 Dec 2015 15:39:01 +0100 Subject: [PATCH] Alarm wake-up when idle (Android M) --- app/src/main/java/eu/faircode/netguard/Widget.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/eu/faircode/netguard/Widget.java b/app/src/main/java/eu/faircode/netguard/Widget.java index 44477a7d..7ad54037 100644 --- a/app/src/main/java/eu/faircode/netguard/Widget.java +++ b/app/src/main/java/eu/faircode/netguard/Widget.java @@ -28,6 +28,7 @@ import android.content.Context; import android.content.Intent; import android.content.SharedPreferences; import android.net.VpnService; +import android.os.Build; import android.preference.PreferenceManager; import android.util.Log; import android.widget.RemoteViews; @@ -67,7 +68,10 @@ public class Widget extends AppWidgetProvider { int auto = Integer.parseInt(prefs.getString("auto_enable", "0")); if (auto > 0) { Log.i(TAG, "Scheduling enabled after minutes=" + auto); - am.set(AlarmManager.RTC_WAKEUP, new Date().getTime() + auto * 60 * 1000L, pi); + if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) + am.set(AlarmManager.RTC_WAKEUP, new Date().getTime() + auto * 60 * 1000L, pi); + else + am.setAndAllowWhileIdle(AlarmManager.RTC_WAKEUP, new Date().getTime() + auto * 60 * 1000L, pi); } } else if (INTENT_ON.equals(intent.getAction()))