我在查找来自原始短信的接收方电话号码时遇到问题.这是我正在尝试的代码:
有人能告诉我如何从原始短信中检索接收者的电话号码.
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(); } }
提前感谢您的帮助!