我为推送通知添加了自定义声音,但它不起作用。我卸载并安装了该应用程序,但仍然无法正常工作。它没有显示任何错误,默认通知也有效。你能告诉我我在哪里失踪吗?
late FlutterLocalNotificationsPlugin flutterLocalNotificationsPlugin;
static const AndroidNotificationChannel channel = AndroidNotificationChannel(
'high_importance_channel', // id
'High Importance Notifications', // title
'This channel is used for important notifications.', // description
sound: RawResourceAndroidNotificationSound('digitalalarm'),
playSound: true,
importance: Importance.high,
);
Future<void> initializeService() async {
flutterLocalNotificationsPlugin = FlutterLocalNotificationsPlugin();
const AndroidInitializationSettings initializationSettingsAndroid =
AndroidInitializationSettings('@mipmap/ic_launcher');
const InitializationSettings initializationSettings =
InitializationSettings(android: initializationSettingsAndroid);
tz.initializeTimeZones();
tz.setLocalLocation(tz.getLocation('Asia/Kolkata'));
await flutterLocalNotificationsPlugin.initialize(
initializationSettings,
onSelectNotification: (payload) async {
if (payload != null && payload.isNotEmpty) {
if (await canLaunch(payload)) {
await launch(
payload,
forceSafariVC: false,
);
} else {
throw "Could not launch URL";
}
}
},
);
Future<void> scheduleNotification(Class _class) async {
{
await flutterLocalNotificationsPlugin.zonedSchedule(
((_class.deadline?.millisecondsSinceEpoch) ?? 0) ~/ 60000,
'Reminder: ${_class.subject}',
'Your assignment is due in 10 minutes',
// ignore: cast_nullable_to_non_nullable
tz.TZDateTime.from(
_class.deadline?.subtract(const Duration(minutes: 10)) ??
DateTime.now(),
tz.local,
),
NotificationDetails(
android: AndroidNotificationDetails(
_class.id,
_class.subject,
'${_class.subject} Assignment reminder',
importance: Importance.max,
priority: Priority.high,
showWhen: false,
color: _class.color,
),
),
androidAllowWhileIdle: true,
uiLocalNotificationDateInterpretation:
UILocalNotificationDateInterpretation.absoluteTime,
payload: _class.link,
);
notifyListeners();
}
}