Skip to content

Commit

Permalink
Use non-exact alarms in Android 14+
Browse files Browse the repository at this point in the history
  • Loading branch information
TSchmiedlechner committed Jun 17, 2024
1 parent 6f12079 commit 9bc85bb
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,15 @@ public override void OnReceive(Context context, Intent intent)
var pending = PendingIntent.GetBroadcast(Application.Context, 0, alarmIntent, PendingIntentFlags.UpdateCurrent | PendingIntentFlags.Immutable);

var alarmManager = (AlarmManager)Application.Context.GetSystemService(Context.AlarmService);
alarmManager.SetExact(AlarmType.ElapsedRealtime, SystemClock.ElapsedRealtime() + 100, pending);

if (Build.VERSION.SdkInt <= BuildVersionCodes.SV2)
{
alarmManager.SetExact(AlarmType.ElapsedRealtime, SystemClock.ElapsedRealtime() + 100, pending);
}
else
{
alarmManager.Set(AlarmType.ElapsedRealtime, SystemClock.ElapsedRealtime() + 100, pending);
}
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" android:versionCode="1"
android:versionName="1.0" package="eu.fiskaltrust.androidlauncher.grpc"
android:installLocation="auto">
<manifest xmlns:android="http://schemas.android.com/apk/res/android" android:versionCode="1" android:versionName="1.0" package="eu.fiskaltrust.androidlauncher.grpc" android:installLocation="auto">
<uses-sdk android:minSdkVersion="24" android:targetSdkVersion="33" />
<application android:allowBackup="true"
android:manageSpaceActivity="eu.fiskaltrust.androidlauncher.common.ManageSpaceActivity"
android:icon="@mipmap/ic_launcher" android:label="@string/app_name" android:supportsRtl="true"
android:theme="@style/AppTheme" android:extractNativeLibs="true"></application>
<application android:allowBackup="true" android:manageSpaceActivity="eu.fiskaltrust.androidlauncher.common.ManageSpaceActivity" android:icon="@mipmap/ic_launcher" android:label="@string/app_name" android:supportsRtl="true" android:theme="@style/AppTheme" android:extractNativeLibs="true"></application>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.ACCESS_MOCK_LOCATION" />
<uses-permission android:name="android.permission.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS" />
<uses-permission android:name="android.permission.SCHEDULE_EXACT_ALARM" android:maxSdkVersion="32" />
<uses-permission android:name="android.permission.USE_EXACT_ALARM" />
<uses-permission android:name="com.android.alarm.permission.SET_ALARM" />
</manifest>
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,15 @@ public override void OnReceive(Context context, Intent intent)
var pending = PendingIntent.GetBroadcast(Application.Context, 0, alarmIntent, PendingIntentFlags.UpdateCurrent | PendingIntentFlags.Immutable);

var alarmManager = (AlarmManager)Application.Context.GetSystemService(Context.AlarmService);
alarmManager.SetExact(AlarmType.ElapsedRealtime, SystemClock.ElapsedRealtime() + 100, pending);

if (Build.VERSION.SdkInt <= BuildVersionCodes.SV2)
{
alarmManager.SetExact(AlarmType.ElapsedRealtime, SystemClock.ElapsedRealtime() + 100, pending);
}
else
{
alarmManager.Set(AlarmType.ElapsedRealtime, SystemClock.ElapsedRealtime() + 100, pending);
}
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,12 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" android:versionCode="1"
android:versionName="1.0" package="eu.fiskaltrust.androidlauncher.http"
android:installLocation="auto">
<manifest xmlns:android="http://schemas.android.com/apk/res/android" android:versionCode="1" android:versionName="1.0" package="eu.fiskaltrust.androidlauncher.http" android:installLocation="auto">
<uses-sdk android:minSdkVersion="24" android:targetSdkVersion="33" />
<application android:allowBackup="true"
android:manageSpaceActivity="eu.fiskaltrust.androidlauncher.common.ManageSpaceActivity"
android:icon="@mipmap/ic_launcher" android:label="@string/app_name" android:supportsRtl="true"
android:theme="@style/AppTheme" android:extractNativeLibs="true"
android:usesCleartextTraffic="true"></application>
<application android:allowBackup="true" android:manageSpaceActivity="eu.fiskaltrust.androidlauncher.common.ManageSpaceActivity" android:icon="@mipmap/ic_launcher" android:label="@string/app_name" android:supportsRtl="true" android:theme="@style/AppTheme" android:extractNativeLibs="true" android:usesCleartextTraffic="true"></application>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS" />
<uses-permission android:name="android.permission.SCHEDULE_EXACT_ALARM" android:maxSdkVersion="32" />
<uses-permission android:name="android.permission.USE_EXACT_ALARM" />
<uses-permission android:name="com.android.alarm.permission.SET_ALARM" />
</manifest>

0 comments on commit 9bc85bb

Please sign in to comment.