[英]scheduled notifications not showing (Flutter_local_notifications)
如果我立即使用 .show() 显示通知,我可以看到通知,但是当我尝试使用 .schedule() 进行安排时,它不会出现。 我可以看到它与 await flutterLocalNotificationsPlugin.pendingNotificationRequests(); 一起安排;
我在一个新的 flutter 项目中尝试了相同的代码,它确实在那里工作,所以我必须在我的实际项目中做一些不同的事情,我只是不知道是什么。
我的清单看起来像这样:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.bap_todo_flutter">
<!-- 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. -->
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>
<uses-permission android:name="android.permission.VIBRATE" />
<application
android:name="io.flutter.app.FlutterApplication"
android:label="bap_todo_flutter"
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|uiMode"
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>
</manifest>
我的状态是这样的:
FlutterLocalNotificationsPlugin flutterLocalNotificationsPlugin =
new FlutterLocalNotificationsPlugin();
@override
void initState() {
super.initState();
var initializationSettingsAndroid =
new AndroidInitializationSettings('@mipmap/ic_launcher');
var initializationSettingsIOS = new IOSInitializationSettings();
var initializationSettings = new InitializationSettings(
initializationSettingsAndroid, initializationSettingsIOS);
flutterLocalNotificationsPlugin.initialize(initializationSettings,
onSelectNotification: onSelectNotification);
}
我正在使用一个简单的 RaisedButton 来安排通知:
RaisedButton(
child: Text("notification"),
onPressed: () async {
var scheduledNotificationDateTime =
new DateTime.now().add(new Duration(seconds: 2));
var androidPlatformChannelSpecifics =
new AndroidNotificationDetails('myalarmapplication.alarm',
'Alarm Channel', 'Flutter Todo Alarm');
var iOSPlatformChannelSpecifics =
new IOSNotificationDetails();
NotificationDetails platformChannelSpecifics =
new NotificationDetails(androidPlatformChannelSpecifics,
iOSPlatformChannelSpecifics);
await flutterLocalNotificationsPlugin
.schedule(
1,
'Alarm',
'Alarm going off',
scheduledNotificationDateTime,
platformChannelSpecifics);
},
),
我正在尝试使用包flutter语言环境通知发送 通知
如果我立即使用.show()显示它,我可以看到通知,但是当我尝试使用.schedule()进行计划时,它不会出现。 我可以看到它与await flutterLocalNotificationsPlugin.pendingNotificationRequests();一起计划。
我在一个新的flutter项目中尝试了相同的代码,它确实在那里工作,所以我必须在实际项目中做一些不同的事情,我只是不知道什么。
我的清单如下所示:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.bap_todo_flutter">
<!-- 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. -->
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>
<uses-permission android:name="android.permission.VIBRATE" />
<application
android:name="io.flutter.app.FlutterApplication"
android:label="bap_todo_flutter"
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|uiMode"
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>
</manifest>
我的状态如下所示:
FlutterLocalNotificationsPlugin flutterLocalNotificationsPlugin =
new FlutterLocalNotificationsPlugin();
@override
void initState() {
super.initState();
var initializationSettingsAndroid =
new AndroidInitializationSettings('@mipmap/ic_launcher');
var initializationSettingsIOS = new IOSInitializationSettings();
var initializationSettings = new InitializationSettings(
initializationSettingsAndroid, initializationSettingsIOS);
flutterLocalNotificationsPlugin.initialize(initializationSettings,
onSelectNotification: onSelectNotification);
}
我正在使用一个简单的RaisedButton来安排通知:
RaisedButton(
child: Text("notification"),
onPressed: () async {
var scheduledNotificationDateTime =
new DateTime.now().add(new Duration(seconds: 2));
var androidPlatformChannelSpecifics =
new AndroidNotificationDetails('myalarmapplication.alarm',
'Alarm Channel', 'Flutter Todo Alarm');
var iOSPlatformChannelSpecifics =
new IOSNotificationDetails();
NotificationDetails platformChannelSpecifics =
new NotificationDetails(androidPlatformChannelSpecifics,
iOSPlatformChannelSpecifics);
await flutterLocalNotificationsPlugin
.schedule(
1,
'Alarm',
'Alarm going off',
scheduledNotificationDateTime,
platformChannelSpecifics);
},
),
我正在尝试使用包flutter语言环境通知发送 通知
如果我立即使用.show()显示它,我可以看到通知,但是当我尝试使用.schedule()进行计划时,它不会出现。 我可以看到它与await flutterLocalNotificationsPlugin.pendingNotificationRequests();一起计划。
我在一个新的flutter项目中尝试了相同的代码,它确实在那里工作,所以我必须在实际项目中做一些不同的事情,我只是不知道什么。
我的清单如下所示:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.bap_todo_flutter">
<!-- 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. -->
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>
<uses-permission android:name="android.permission.VIBRATE" />
<application
android:name="io.flutter.app.FlutterApplication"
android:label="bap_todo_flutter"
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|uiMode"
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>
</manifest>
我的状态如下所示:
FlutterLocalNotificationsPlugin flutterLocalNotificationsPlugin =
new FlutterLocalNotificationsPlugin();
@override
void initState() {
super.initState();
var initializationSettingsAndroid =
new AndroidInitializationSettings('@mipmap/ic_launcher');
var initializationSettingsIOS = new IOSInitializationSettings();
var initializationSettings = new InitializationSettings(
initializationSettingsAndroid, initializationSettingsIOS);
flutterLocalNotificationsPlugin.initialize(initializationSettings,
onSelectNotification: onSelectNotification);
}
我正在使用一个简单的RaisedButton来安排通知:
RaisedButton(
child: Text("notification"),
onPressed: () async {
var scheduledNotificationDateTime =
new DateTime.now().add(new Duration(seconds: 2));
var androidPlatformChannelSpecifics =
new AndroidNotificationDetails('myalarmapplication.alarm',
'Alarm Channel', 'Flutter Todo Alarm');
var iOSPlatformChannelSpecifics =
new IOSNotificationDetails();
NotificationDetails platformChannelSpecifics =
new NotificationDetails(androidPlatformChannelSpecifics,
iOSPlatformChannelSpecifics);
await flutterLocalNotificationsPlugin
.schedule(
1,
'Alarm',
'Alarm going off',
scheduledNotificationDateTime,
platformChannelSpecifics);
},
),
添加此额外的行
flutterLocalNotificationsPlugin .schedule(
...
...
androidAllowWhileIdle: 真);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.