Custom Sound is not working when app is in background or terminated #907
Labels
bug
Something isn't working
closed by bot
This issue was automatically closed due to inactivity
in triage
This issue is waiting for first service response
Rules
To report a bug and help us to provide the solution as fast as possible, please follow the instructions below:
Custom Sound is not working when app is in background or terminated
A clear and concise description of what the bug is.
OBS: avoid to use the expression "its not working" or "is working" or any other variation. These expressions can mean anything and at same time doesn´t bring any useful information. As soon you rewrite these expressions, you naturally going to be more precise and clear.
2 - Provide us as much information as possible
To help us to understand your issue, provide with your bug report all the relevant informations, such as:
pubspec.yaml
(at least all notification plugins)awesome_notifications: ^0.8.2
How are you initializing the plugin
AwesomeNotifications().initialize(
null,
[
NotificationChannel(
channelKey: "alert",
channelName: "alert",
channelDescription: "This is for Person Detection",
playSound: true,
soundSource: "resource://raw/res_alert",
criticalAlerts: true,
importance: NotificationImportance.High,
enableVibration: true,
onlyAlertOnce: false,
defaultRingtoneType: DefaultRingtoneType.Ringtone,
),
],
);
How are you creating the notification
Future handleBackgroundMessage(RemoteMessage message) async {
String? title = message.notification?.title;
String? body = message.notification?.body;
print("Title : ${title}");
print("Body : ${body}");
print("Payload : ${message.data}");
await AwesomeNotifications().createNotification(
content: NotificationContent(
id: 1359,
channelKey: "alert",
title: title,
body: body,
wakeUpScreen: true,
category: NotificationCategory.Call,
customSound: "resource://raw/res_alert",
autoDismissible: false,
criticalAlert: true,
),
actionButtons: [
NotificationActionButton(key: "ok", label: "OK"),
NotificationActionButton(key: "cancel", label: "Cancel"),
]
);
}
flutter doctor
commandDoctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel stable, 3.13.2, on macOS 13.5.1 22G90 darwin-x64, locale en-GB)
[✓] Android toolchain - develop for Android devices (Android SDK version 34.0.0)
[✓] Xcode - develop for iOS and macOS (Xcode 15.0.1)
[✓] Chrome - develop for the web
[✓] Android Studio (version 2022.3)
[✓] VS Code (version 1.84.2)
[✓] Connected device (3 available)
! Error: Browsing on the local area network for Brit’s iPhone. Ensure the device is unlocked and attached with a cable or associated with the same local area network as this Mac.
The device must be opted into Developer Mode to connect wirelessly. (code -27)
! Error: Browsing on the local area network for Rahil’s iPhone. Ensure the device is unlocked and attached with a cable or associated with the same local area network as this Mac.
The device must be opted into Developer Mode to connect wirelessly. (code -27)
[✓] Network resources
• No issues found!
OBS: To post a source code in your issue, please use the markdown below:
'''
class PushNotificationService {
final firebaseInstance = FirebaseMessaging.instance;
Future initNotification() async {
await firebaseInstance.requestPermission(
alert: true, badge: true, sound: true, criticalAlert: true);
await firebaseInstance.subscribeToTopic("alert");
final fcmToken = await firebaseInstance.getToken();
print(fcmToken);
}
}
Future handleBackgroundMessage(RemoteMessage message) async {
String? title = message.notification?.title;
String? body = message.notification?.body;
print("Title : ${title}");
print("Body : ${body}");
print("Payload : ${message.data}");
await AwesomeNotifications().createNotification(
content: NotificationContent(
id: 1359,
channelKey: "alert",
title: title,
body: body,
wakeUpScreen: true,
category: NotificationCategory.Call,
customSound: "resource://raw/res_alert",
autoDismissible: false,
criticalAlert: true,
),
actionButtons: [
NotificationActionButton(key: "ok", label: "OK"),
NotificationActionButton(key: "cancel", label: "Cancel"),
]
);
}
'''
3 - How To Reproduce the Error
Steps to reproduce the behavior:
...or if you prefer, you can provide us a simple example app on GitHub with the issue already reproduced instead of the steps 2 and 3.
4 - Expected behavior
I want to set custom sound in background notification in handle background message.
The text was updated successfully, but these errors were encountered: