3

How can I get the destination address from a sms(so that I will have the mobile number of my device) when I receive a new sms in my BroadcastReceiver?

the code:

TelephonyManager tMgr = (TelephonyManager) context
.getSystemService(Context.TELEPHONY_SERVICE);
String myPhoneNumber = tMgr.getLine1Number();

will not work since the getLine1Number() method in TelephonyManager retrieves the data in the "phone number" stored on the SIM card (NOT the phone number bound to the user's account) - this is often either wrong or non-existent, depending on the network provider it was shipped from.

I already also checked the SMSMessage Class and I couldn't find any method helping me.

Emmanuel
  • 216
  • 2
  • 11

1 Answers1

2

If you're not satisfied with getLine1Number(), here is what you can try:

Here is an answer that shows how to fetch data about sent SMSes, including the destination address (which is what you need, I think). The answer is about sent SMSes, but if you change "content://sms/sent" to "content://sms/inbox", you should be able to access the received SMS messages. I'm not sure if the inbox SMSes also contain the destination address, but it's worth checking.

Community
  • 1
  • 1
Jakub Wasilewski
  • 2,916
  • 22
  • 27
  • Checked it your way and it does not contain the destination address. Thank you for your reply thought. – Emmanuel Oct 15 '12 at 13:10
  • Hm, then I think there is no way to get the destination from the SMS - the data in `sms/inbox` is all the SMS application itself knows. – Jakub Wasilewski Oct 15 '12 at 13:23