21st Oct 2018

How To Listen for SMS using Flutter - SMS App Part 2


Author

Mayank Bajaj

Software Engineer

4 min readMobile Applications
4 min readMobile Applications

Flutter app development service

In continuation with the previous blog, we would continue to build our new basic SMS app using Flutter. In this blog, we would see how we can add the functionality of listening for incoming SMS messages on the device.

We are using the sms package for building this app. Please check out the previous blog to get the brief intro on how to use this package.

Create an instance of sms receiver.

SmsReceiver receiver = new SmsReceiver();

Now we need to use the receiver we created above to bind a listener for the SMS message received event. We use the .listen method on the onSmsReceived event of the receiver which excepts a callback and gives us the received message object as an argument whenever a new message is received by the device.

receiver.onSmsReceived.listen((SmsMessage msg) =>
    #Do something
);

SMSMessage, contains sender, message and date of the SMS message. Internal implementation of SMSMessage class is given below:

class SMSMessage {
  String message;
  String sender;
  var date;
}

Now you can start a message listener like shown above, and detect all the incoming SMS messages on the user's phone.

In the next blog, we will set up a mailer, which will be used to email the incoming SMS message to a particular email.

We bring the best in technology combined with an Agile process which results in higher efficiency and desired results for our clients.

Talk to us!

LATEST FROM OUR BLOG

Building a Facebook Echo-Bot in Python

Gartner estimates that by 2020, chatbots will be handling 85 percent of customer-service interactions; they are already handling about 30 percent of transactions now.

Read more

How to Send an Email from Flutter - SMS App Part 3

In this blog, we will see how we can send emails from our flutter application using mailgun credentials. This post is in continuation of the Flutter SMS app series.

Read more

How To Listen for SMS using Flutter - SMS App Part 2

In continuation with the previous blog, we would continue to build our new basic SMS app using Flutter. In this blog, we would see how we can add the functionality of listening for incoming SMS messages on the device.

Read more