jgithaiga / flutter_sms_inbox

Flutter SMS Inbox (Android only)
MIT License
15 stars 17 forks source link

Checking what SIM/Phone number received a message #15

Closed williamluke4 closed 2 years ago

williamluke4 commented 2 years ago

Hey Julius, Thank you so much for creating this.

I'm currently using this here https://github.com/williamluke4/myPesa to extract transactions from M-PESA.

Was wondering how easy it would be to check what phone number or sim a message was sent to (i.e for multi-sim devices). I've had a brief dig around and it does not seem as trivial as I would have hoped.

jgithaiga commented 2 years ago

Hi @williamluke4,

You can get the phone number from SmsMessage instance as address e.g.

final messages = await _query.querySms(
  kinds: [SmsQueryKind.inbox, SmsQueryKind.sent],
  // address: '+254712345789',
  count: 10,
);
debugPrint('sms inbox messages: ${messages.length}');

for (var message in messages) {
  debugPrint('phone number: ${message.address}');
}
williamluke4 commented 8 months ago

Hey @jgithaiga,

I have finally had some time to have a look at this but it seems that the address returned here is the sender's address not the recipient's address.

As you can see below the following message was sent from Safaricom/MPESA to my number but the address shows MPESA, not my number.

image

williamluke4 commented 8 months ago

Adding the subId then allowes you to look up the phone number from carrierInfo

https://github.com/jgithaiga/flutter_sms_inbox/pull/21