shounakmulay / Telephony

Flutter plugin for telephony features like query device sms directory, listen for incoming messages, retrieve various network parameters, etc.
https://telephony.shounakmulay.dev
MIT License
140 stars 132 forks source link

Listening to incoming messages #174

Open Trend74X opened 1 year ago

Trend74X commented 1 year ago

I am using telephony: 0.2.0, flutter version: 3.3.8

I am trying to listen to message received, it works when the messages is sent by the service providers, but it doenst work when the sms is sent from another mobiles.

is anyone else experiencing this problem? is there a solution

I have also added to android manifest files.

` onBackgroundMessage(SmsMessage message) { debugPrint("onBackgroundMessage called"); mainController.newSMSReceived(message); }

@override void initState() { super.initState(); listenToNewSms(); }

listenToNewSms() async { final bool? result = await telephony.requestPhoneAndSmsPermissions;

if (result != null && result) {
  telephony.listenIncomingSms(
    onNewMessage: (SmsMessage message) {
      onMessage(message);
    }, 
    onBackgroundMessage: onBackgroundMessage
  );
}

if (!mounted) return;

}

onMessage(message) async { mainController.newSMSReceived(message); } `

aman-singh7 commented 1 year ago

Yes, I am also facing this issue.