Ayush783 / readsms_plugin

Flutter plugin for reading sms on Android.
https://pub.dev/packages/readsms
MIT License
6 stars 10 forks source link

Reading of message #4

Closed dk-a-dev closed 3 months ago

dk-a-dev commented 5 months ago

Reads the last few characters of the message(SMS) only @Ayush783 I will be grateful if u can fix this or give any alternate solution

Ali3Jamous commented 4 months ago

I made a workaround for this issue.. I know it's not that excellent, but it worked for me 😅 For the code in the example, you can add a Timerand a Stringthis way:

Timer? smsGrouper;
String finalSMS = '';

_plugin.smsStream.listen((event) {
  smsGrouper?.cancel();
  finalSMS += event.body;
  smsGrouper = Timer(const Duration(seconds: 3), () {
    setState(() {
      sms = finalSMS;
      sender = event.sender;
      time = event.timeReceived.toString();
    });
      finalSMS = '';
  });
});

The Timerwaits 3 seconds to group the SMS part with next one before dealing with the SMS. If the duration passed without receiving any new part, it assumes that the SMS has finished. You may change the duration due to your needs,

dk-a-dev commented 3 months ago

Thanks Bud