4

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 Answers1

1

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: {}
}
Teh Sunn Liu
  • 487
  • 2
  • 14
Leo
  • 66
  • 7
  • @Teh Sunn Liu Where exactly do we add this? Inside flutter or Firebase? Kindly explain – Lefty Feb 23 '21 at 11:46
  • @Lefty This answer is not posted by me :). I'm just an editor. This can be added to your HTTP request usually from the server. follow the link to know more https://firebase.google.com/docs/reference/fcm/rest/v1/projects.messages#androidconfig – Teh Sunn Liu Feb 23 '21 at 18:13
  • @Teh Sunn Liu , its all good, I did manage to get it working. Thanks – Lefty Feb 23 '21 at 21:03
  • I added it to the ```notification``` and it worked as well! – Ricardo Oscar Kanitz Mar 02 '21 at 08:23