简体   繁体   中英

Flutter: Schedule notification not working

I am developing a app using Flutter.

To show notification I an using flutter_local_notifications package.

I am getting notification, but schedule notification is not working.

Similar question was asked here How do I schedule a notification in Flutter? , but my receiver is already inside the application tag.

Here is my manifest

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

<!-- The INTERNET permission is required for development. Specifically,
     flutter needs it to communicate with the running application
     to allow setting breakpoints, to provide hot reload, etc.
-->
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>
<uses-permission android:name="android.permission.WAKE_LOCK"/>

<!-- io.flutter.app.FlutterApplication is an android.app.Application that
     calls FlutterMain.startInitialization(this); in its onCreate method.
     In most cases you can leave this as-is, but you if you want to provide
     additional functionality it is fine to subclass or reimplement
     FlutterApplication and put your custom class here. -->
<application
    android:name="io.flutter.app.FlutterApplication"
    android:label="gayatri_monitor"
    android:icon="@mipmap/ic_launcher">
    <receiver android:name="com.dexterous.flutterlocalnotifications.ScheduledNotificationReceiver" />
    <receiver android:name="com.dexterous.flutterlocalnotifications.ScheduledNotificationBootReceiver">
        <intent-filter>
            <action android:name="android.intent.action.BOOT_COMPLETED"></action>
        </intent-filter>
    </receiver>
    <activity
        android:name=".MainActivity"
        android:launchMode="singleTop"
        android:theme="@style/LaunchTheme"
        android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale|layoutDirection|fontScale|screenLayout|density"
        android:hardwareAccelerated="true"
        android:windowSoftInputMode="adjustResize">
        <!-- This keeps the window background of the activity showing
             until Flutter renders its first frame. It can be removed if
             there is no splash screen (such as the default splash screen
             defined in @style/LaunchTheme). -->
        <meta-data
            android:name="io.flutter.app.android.SplashScreenUntilFirstFrame"
            android:value="true" />
        <intent-filter>
            <action android:name="android.intent.action.MAIN"/>
            <category android:name="android.intent.category.LAUNCHER"/>
        </intent-filter>
    </activity>
</application>

adding this inside application of your manifest might solve your problem

   <service          android:name="com.folk.localnotifications.services.LocalNotificationsService"
 android:exported="false" />

Remember: com.folk is used for this project only. For different project, go to your manifest, see package name and edit accordingly.

I had the same problem but couldn't find the solution online, however, later I did figure out running flutter clean then flutter run seems to do the trick for me.

You have to essentially clean your build and rebuild it again. Hope that helps.

我遇到了同样的问题,我通过为我发出的每个 android 通知创建一个单独的通知通道来解决它,即使它们具有相同的优先级。

In my case, I just added the following inside initState()

var initializationSettingsAndroid =
        AndroidInitializationSettings('@mipmap/ic_launcher');
        var initializationSettingsIOS = IOSInitializationSettings();
        var initializationSettings = InitializationSettings(
            android: initializationSettingsAndroid, iOS: initializationSettingsIOS);
        flutterLocalNotificationsPlugin.initialize(
          initializationSettings,
        );

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM