Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

android 13 scheduled alarms vs exact alarms #1906

Closed
hichaudh opened this issue Feb 28, 2023 · 7 comments · Fixed by #2052
Closed

android 13 scheduled alarms vs exact alarms #1906

hichaudh opened this issue Feb 28, 2023 · 7 comments · Fixed by #2052

Comments

@hichaudh
Copy link

according to android 14. apps using SCHEDULE_EXACT_ALARM will not be enabled by default: https://developer.android.com/about/versions/14/changes/schedule-exact-alarms

Just curious whether this has been recognized by the plugin team and whether there will be any necessary changes to usage of the plugin etc.
Would also be nice to see an update to documentation whether on here or pub.dev

@hichaudh hichaudh changed the title android 14 scheduled alarms vs exact alarms android 13 scheduled alarms vs exact alarms Mar 1, 2023
@MaikuB
Copy link
Owner

MaikuB commented Mar 12, 2023

Could you to help look into this? There isn't a team that works on the plugin as it's maintained by myself (during my spare time) with contributions by the community

@pritish-thub
Copy link

This will help https://www.youtube.com/watch?v=aQTvI8L-mZs

@FriesI23
Copy link

It seems that "SCHEDULE_EXACT_ALARM" is limited by the system,

A simple workflow is to catch PlatformError, e.g.

try {
  await flutterLocalNotificationsPlugin.zonedSchedule(
        0,
        'scheduled title',
        'scheduled body',
        tz.TZDateTime.now(tz.local).add(const Duration(seconds: 5)),
        const NotificationDetails(
            android: AndroidNotificationDetails(
                'your channel id', 'your channel name',
                channelDescription: 'your channel description')),
        androidScheduleMode: AndroidScheduleMode.exactAllowWhileIdle,
        uiLocalNotificationDateInterpretation:
            UILocalNotificationDateInterpretation.absoluteTime);
} on PlatformException catch (e) {
    debugPrint(e.message); //Caller com.your.package needs to hold android.permission.SCHEDULE_EXACT_ALARM or android.permission.USE_EXACT_ALARM to set exact alarms
    // handle failure logic here
}

@pranavo72bex
Copy link

pranavo72bex commented Apr 19, 2023

Any update on this issue. I am facing this issue in android 14.

flutter_local_notifications: ^14.0.0-dev.4

Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel stable, 3.7.7, on macOS 13.2.1 22D68 darwin-arm64, locale en-NP)
[✓] Android toolchain - develop for Android devices (Android SDK version 32.1.0-rc1)
[✓] Xcode - develop for iOS and macOS (Xcode 14.3)
[✓] Chrome - develop for the web
[✓] Android Studio (version 2022.1)
[✓] VS Code (version 1.77.3)
[✓] Connected device (2 available)
[✓] HTTP Host Availability

• No issues found!

@timobaehr
Copy link

Happeing on Android 13, when calling await flutterLocalNotificationsPlugin.zonedSchedule

Affected devices (all Android 13):

  • Pixel 7 Pro
  • Galaxy S21 5G
  • Galaxy S23 Ultra

Not reproducable so far on:

  • Pixel 6 Pro, Android 14

flutter_local_notifications version used:

  • 13.0.0

Stacktrace:

Non-fatal Exception: io.flutter.plugins.firebase.crashlytics.FlutterError: PlatformException(error, Caller com.ehwplus needs to hold android.permission.SCHEDULE_EXACT_ALARM or android.permission.USE_EXACT_ALARM to set exact alarms., null, java.lang.SecurityException: Caller com.ehwplus needs to hold android.permission.SCHEDULE_EXACT_ALARM or android.permission.USE_EXACT_ALARM to set exact alarms.
	at android.os.Parcel.createExceptionOrNull(Parcel.java:3057)
	at android.os.Parcel.createException(Parcel.java:3041)
	at android.os.Parcel.readException(Parcel.java:3024)
	at android.os.Parcel.readException(Parcel.java:2966)
	at android.app.IAlarmManager$Stub$Proxy.set(IAlarmManager.java:311)
	at android.app.AlarmManager.setImpl(AlarmManager.java:1084)
	at android.app.AlarmManager.setImpl(AlarmManager.java:1044)
	at android.app.AlarmManager.setExactAndAllowWhileIdle(AlarmManager.java:1312)
	at androidx.core.app.e$b.b(Unknown Source:0)
	at androidx.core.app.e.b(Unknown Source:6)
	at com.dexterous.flutterlocalnotifications.FlutterLocalNotificationsPlugin.zonedScheduleNotification(Unknown Source:67)
	at com.dexterous.flutterlocalnotifications.FlutterLocalNotificationsPlugin.zonedSchedule(Unknown Source:26)
	at com.dexterous.flutterlocalnotifications.FlutterLocalNotificationsPlugin.onMethodCall(Unknown Source:361)

I cannot reproduce this bad behaviour on other devices. Reported via Crashlytics.

@MaikuB
Copy link
Owner

MaikuB commented May 12, 2023

@timobaehr your issue isn't directly (emphasis on directly) related to what was raised by @hichaudh. The point raised by @hichaudh is around how to handle behavioural changes in Android 14. What you're seeing isn't a device-specific either that trying to reproduce this on different devices won't help. If you look the stack trace then this permissions related that means app had a permission revoked that impacts the ability to send a notification at the exact time. Your issue was already reported in #1526 and 14.0.0 made some changes to log an error instead of resulting in a crash and also allowed apps to schedule notifications with inexact timings should they choose to do so

@MaikuB
Copy link
Owner

MaikuB commented Jul 16, 2023

Changes have been done as part of the 16.0.0 prerelease relating to this and details have been added to the readme as well

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
6 participants