Executing in Background
backgrounMessageHandler(SmsMessage message) async {
// Handle background message
Telephony.insatnce.sendSms(to: "123456789", message: "Message from background")
}
void main() {
runApp(MyApp());
}
class _MyAppState extends State<MyApp> {
String _message;
// This will not work as the instance will be replaced by
// the one in background.
final telephony = Telephony.instance;
@override
void initState() {
super.initState();
// You should make sure call to instance is made every time
// app comes to foreground
final inbox = Telephony.insatnce.getInboxSms()
}Last updated