Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get phone number of SMS recipient in Android

Tags:

android

sms

pdu

I have seen many questions asking how to get the SMS sender's phone number, but not the recipient's phone number. I have used the tool on this site to generate a PDU and can see the recipient's phone number in it:

Useful PDU details and PDU translation tool

However, I don't see anywhere in the SmsMessage class provided by Android where I can get the recipient's phone number. The reason I want to do this is that I have a Dual SIM phone, but don't see anywhere in Android where I can determine what SIM port is being used for the incoming SMS. At the very least, I want to look at each SMS message and determine what phone number they were sent to.

This question seems very similar to mine but with no answers:

How to get SMS recipient's phone number in Android

My question is different because I have detailed a link to a site about PDUs, which may be useful for extracting the phone number form the raw PDU bytes that the SmsMessage class provides.

Any ideas?

like image 228
gonzobrains Avatar asked May 13 '13 19:05

gonzobrains


1 Answers

It depends from which point you watch SMS message. SMS PDU lies on top of MAP protocol.

When you send SMS message, phone puts recipient number in TP-Destination within a PDU, when you receive SMS message, there is no recipient number anywhere. The reason for this is how SMS works. When someone sends you SMS, GSM network on his side request SRIsm message for you, that means his HLR will try to find you either in his home network, or through your home HLR. The response from HLR is IMSI number (your SIMcard) and VLR/MSC number, to where sender network must send SMS. In second packet, which is actually SMS message (Forward-MT), therefore is only your IMSI number. Since you have dual SIM, you can try to find based on this number, to which SIM card is SMS destined. Note that IMSI number is not part of the PDU but rather lower MAP protocol.

like image 158
Marvin Avatar answered Sep 20 '22 18:09

Marvin