我想创建一个应用程序,我只想得到最近收到的短信的发件人信息(电话号码,日期),我想发送回复消息那个特定的数字。我怎样才能访问最近收到的短信的编号在android
我试过这段代码,怎样才能得到最近收到的短信的发件人信息?
Bundle bundle = intent.getExtras();
SmsMessage[] msgs = null;
String string = "";
String phone = "";
if (bundle != null)
{
//---receive the SMS message--
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]);
phone = msgs[i].getOriginatingAddress(); // Here you can get the phone number of SMS sender.
string += msgs[i].getMessageBody().toString(); // Here you can get the message body.
}
}
反正是有得到的消息发送号码不延长广播接收器?反正从消息日志存取权限?
@Hardik中,我应该延长广播reciever? – 2013-03-12 06:42:23
为什么你不想扩展'BroadcastReceiver'?可以从收件箱读取消息(通过“ContentProvider”)[但不是每个设备](http://android-developers.blogspot.ch/2010/05/be-careful-with-content-providers.html) ! – faceman 2013-03-12 07:32:45