Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Flutter - How can I create an Incoming Call Notification?

I'm building an app that allows users to call eachother using the agora_rtc_engine. I'm currently stuck trying to implement a notification system that will alert users when they receive a call.

I'm using Firebase Messaging for notifications.

I have the following questions:

  1. How would I go about replacing the default notification card with a custom one that has buttons for answering or declining the call?

  2. How can I specify the amount of time the notification stays on screen? An incoming call rings for about 30 seconds before closing, so I would like my notification card to appear on screen for that period of time.

I've been looking at the flutter_local_notifications, but they don't have a "incoming call" notification style.

Any piece of information is highly appreciated. Thank you!

like image 966
Ionut Vasile Avatar asked May 04 '20 15:05

Ionut Vasile


People also ask

How do I create a notification on flutter?

Displaying a notification in Flutter To display a notification, we need to create a platform-specific NotificationDetails instance, which takes in arguments that are unique to each platform. AndroidNotificationDetails handles the configuration of notifications in Android devices.


Video Answer


1 Answers

I suggest you trying to use Firebase Cloud Messaging.

Check out the "Setting the lifespan of a message" section of the official documentation: https://firebase.google.com/docs/cloud-messaging/concept-options#ttl

There you will find an example of a cloud message with time_to_live parameter - it determines how long will the notification be active on the recipient's device.

Here is an example of a request that includes TTL (taken from the official documentation):

{
  "message":{
    "token":"bk3RNwTe3H0:CI2k_HHwgIpoDKCIZvvDMExUdFQ3P1...",
    "data":{
      "Nick" : "Mario",
      "body" : "great match!",
      "Room" : "PortugalVSDenmark"
    },
    "apns":{
      "headers":{
        "apns-expiration":"1604750400"
      }
    },
    "android":{
      "ttl":"4500s"
    },
    "webpush":{
      "headers":{
        "TTL":"4500"
      }
    }
  }
}
like image 79
OlegBezr Avatar answered Oct 22 '22 06:10

OlegBezr