4
votes

So I have enabled firebase messaging on my futter app everything works fine but, when I receive the notification in my app it wont sound or vibrate, neither android or ios. I believe FCM does it by default, I also have "IosNotificationSettings(sound: true, badge: true, alert: true)", but the notification just come mute. Do you guys have any Idea what could be happening? I searched for this situation but couldnt find anything about it. Thanks in advance for your help.

class _HomeScreenState extends State<HomeScreen>
with SingleTickerProviderStateMixin {

 String _homeScreenText = "Waiting for token...";

 final FirebaseMessaging _firebaseMessaging = FirebaseMessaging();

 static const String contato = "contato";

 TabController _tabController;

 @override
 void initState() {
    _tabController = new TabController(length: 5, vsync: this);
    super.initState();

    _firebaseMessaging.configure(
       onMessage: (Map<String, dynamic> message) {
         print('on message $message');
       },
       onResume: (Map<String, dynamic> message) {
         print('on resume $message');
       },    
       onLaunch: (Map<String, dynamic> message) {
       print('on launch $message');
       },
      );

     _firebaseMessaging.requestNotificationPermissions(
         const IosNotificationSettings(sound: true, badge: true, alert: true));
     _firebaseMessaging.onIosSettingsRegistered
       .listen((IosNotificationSettings settings) {
         print("Settings registered: $settings");
      });
     _firebaseMessaging.getToken().then((String token) {
       assert(token != null);
       setState(() {
     _homeScreenText = "Push Messaging token: $token";
     });
     print(_homeScreenText);
     });

     _firebaseMessaging.getToken().then((token) {
     Firestore.instance.collection("pushtokens").document().setData({"devtoken": token});
     });
    }
1

1 Answers

1
votes

To enable sound on notification you need to add sound: default part in notification data like this:

{
  data: {
    google.sent_time: 1588863942303, 
    click_action: FLUTTER_NOTIFICATION_CLICK, 
    google.original_priority: high,
    collapse_key: YourPackageName,
    google.delivered_priority: high,
    sound: default,
    from: YourSenderId,
    google.message_id: 0:1588863942508709%a91ceea4a91ceea4,
    google.ttl: 60
  },
  notification: {}
}