I want to disable sound for incoming notification when the user turn of the notification switch in my app.
I also read official documentation but couldn't find anything helpful.
Is there any way? Also I added property playsound: false but it's not working for me, I still got android default notification sound.
I tried This package for local notifications but didn't find what I am looking for!
Refer my code below for sending notification on android.
import 'package:flutter_local_notifications/flutter_local_notifications.dart';
class MusicNotification {
final FlutterLocalNotificationsPlugin flutterLocalNotificationsPlugin =
FlutterLocalNotificationsPlugin();
Future<void> init() async {
const AndroidInitializationSettings initializationSettingsAndroid =
AndroidInitializationSettings("@mipmap/ic_launcher");
const DarwinInitializationSettings initializationSettingsIOS =
DarwinInitializationSettings();
const InitializationSettings initializationSettings =
InitializationSettings(
android: initializationSettingsAndroid,
iOS: initializationSettingsIOS,
);
await flutterLocalNotificationsPlugin.initialize(
initializationSettings,
);
}
void showNotificationAndroid(String title, String value) async {
const AndroidNotificationDetails androidNotificationDetails =
AndroidNotificationDetails(
'Music123',
'Music',
channelDescription: 'Music Notification',
importance: Importance.max,
priority: Priority.high,
playSound: false,
ticker: 'ticker',
);
int notification_id = 1;
const NotificationDetails notificationDetails =
NotificationDetails(android: androidNotificationDetails);
await flutterLocalNotificationsPlugin.show(
notification_id, title, value, notificationDetails,
payload: 'Not present');
}
}
and this is for calling notification event
MusicNotification().showNotificationAndroid(
'title',
'value');
This should be handled by your backend service. You can mute the sound by not sending "sound" key in your Cloud Messaging API. Read more here
One of the techniques can be deleting your old notification channel with sound and recreating the channel with no sound. This package is handy for dealing with notifications in flutter.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With