Skip to content

Instantly share code, notes, and snippets.

telephony.listenIncomingSms(
onNewMessage: (SmsMessage message) {
// Handle message
},
onBackgroundMessage: backgroundMessageHandler
);
backgrounMessageHandler(SmsMessage message) async {
//Handle background message
// You can also call other plugin in here
}
void main() {
runApp(MyApp());
}
@shounakmulay
shounakmulay / listen_foreground.dart
Last active June 6, 2021 07:39
List to incoming sms in foreground.
telephony.listenIncomingSms(
onNewMessage: (SmsMessage message) {
// Handle message
},
listenInBackground = false
);
@shounakmulay
shounakmulay / telephony_instance.dart
Created June 6, 2021 07:32
Get telephony instance
import 'package:telephony/telephony.dart';
final Telephony telephony = Telephony.instance;
@shounakmulay
shounakmulay / AndroidManifest.xml
Created June 6, 2021 07:07
Adding the telephony incoming sms broadcast receiver to android manifest.
<manifest>
<uses-permission android:name="android.permission.RECEIVE_SMS"/>
<application>
...
...
<receiver android:name="com.shounakmulay.telephony.sms.IncomingSmsReceiver"
android:permission="android.permission.BROADCAST_SMS" android:exported="true">
<intent-filter>