Android:如何从原始短信中获取发送者和接收者的电话号码 [英] Android: how to get sender and receiver phone number from raw sms
本文介绍了Android:如何从原始短信中获取发送者和接收者的电话号码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在从原始短信中找出接收者的电话号码时遇到问题.这是我正在尝试的代码:
I have a problem in finding out the receiver phone number from the incoming raw SMS. Here is the code that I am trying:
有人可以告诉我如何从原始短信中检索接收方电话号码.
Can someone tell me how to retrieve receiver phonenumber 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();
}
}
谢谢您的帮助!
推荐答案
SMS由MAP交付,MAP是SIM与MSC/GMSC/SMSC之间的协议(某些详细信息此.因此,据我所知,可能由于上述原因,没有针对您所需的直接API.
SMS is delivered by MAP which is a protocol between SIM and the MSC/GMSC/SMSC (Some details here). The SIM is already identified in this association. Also the SMS DELIVER does not include the recipient address. See this. So, as far as i understand there is not an direct API for what you desired maybe because of the above reasons.
这篇关于Android:如何从原始短信中获取发送者和接收者的电话号码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文