I have a problem finding the recipient's phone number from incoming raw SMS. Here is the code I'm trying to do:
Can someone tell me how to get the recipient's phone number from raw SMS.
public class SMSReceiver extends BroadcastReceiver { private Context context; @Override public void onReceive(Context context, Intent intent) { this.context = context; // Parse the SMS. Bundle bundle = intent.getExtras(); SmsMessage[] msgs = null; String str = ""; if (bundle != null) { // Retrieve the SMS. Object[] pdus = (Object[]) bundle.get("pdus"); msgs = new SmsMessage[pdus.length]; for (int i=0; i<msgs.length; i++) { msgs[i] = SmsMessage.createFromPdu((byte[])pdus[i]); //appending to str String. str += "OriginatingAddress: "; str += msgs[i].getOriginatingAddress(); str += " :\n"; str += " :\n"; str += "DisplayOriginatingAddress: "; str += msgs[i].getDisplayOriginatingAddress(); str += " :\n"; str += " :\n"; str += "DisplayMessageBody: "; str += msgs[i].getDisplayMessageBody(); str += " :\n"; str += " :\n"; str += "MessageBody: "; str += msgs[i].getMessageBody(); } Toast.makeText(context, str, Toast.LENGTH_SHORT).show(); } }
Thanks for the help in advance!
source share