MaikuB / flutter_local_notifications

A Flutter plugin for displaying local notifications on Android, iOS, macOS and Linux
2.47k stars 1.4k forks source link

Android: Scheduled Notifications are not shown after restart on Android 11 #2396

Closed davidsturm96 closed 2 months ago

davidsturm96 commented 2 months ago

My problem is quite similar to this one: https://github.com/MaikuB/flutter_local_notifications/issues/2209

I upgraded this package from 14.1.5 to 17.2.2.

Before the upgrade, everything worked without a problem.

After the upgrade, scheduled notifications stopped working, if the device is restarted before the notification is shown.

This bug only happened to me on android 11 (Xiaomi), on android 14 (Xiaomi), this works fine. Scheduled notifications in foreground or closed app state work as expected on android 11.

I tested this on a physical device.

The setup of my AndroidManifest.xml is like this:

<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.foo">

<uses-permission android:name="android.permission.RECORD_AUDIO"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.VIBRATE"/>
<uses-permission android:name="android.permission.INTERNET" />

<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>
<uses-permission android:name="android.permission.SCHEDULE_EXACT_ALARM" android:maxSdkVersion="32" />
<uses-permission android:name="android.permission.USE_EXACT_ALARM" />

<queries>
    <intent>
        <action android:name="android.intent.action.VIEW" />
        <data android:scheme="https" />
    </intent>
    <intent>
        <action android:name="android.intent.action.SENDTO" />
        <data android:scheme="mailto" />
    </intent>
</queries>

 <application
      android:requestLegacyExternalStorage="true"
      android:label="foo"
      android:name="${applicationName}"
      android:icon="@mipmap/ic_launcher">

      <receiver android:exported="false" android:name="com.dexterous.flutterlocalnotifications.ScheduledNotificationReceiver" />
      <receiver android:exported="false" android:name="com.dexterous.flutterlocalnotifications.ScheduledNotificationBootReceiver">

         <intent-filter>
             <action android:name="android.intent.action.BOOT_COMPLETED"/>
             <action android:name="android.intent.action.MY_PACKAGE_REPLACED"/>
             <action android:name="android.intent.action.QUICKBOOT_POWERON" />
             <action android:name="com.htc.intent.action.QUICKBOOT_POWERON"/>
         </intent-filter>
      </receiver>

     <receiver android:exported="false" android:name="com.dexterous.flutterlocalnotifications.ActionBroadcastReceiver" />

Power saving mode is turned off for the app.

Any ideas what I am doing wrong?

davidsturm96 commented 2 months ago

Apparently, the problem was caused by the security settings. There, I had to explicitly enable the auto start permission for my app.