import android
droid = android.Android()
SMSmsgs = droid.smsGetMessages(False, 'inbox').result
for message in SMSmsgs:
print 'From: '+message['address']+' > '+message['body']+'\n'
我需要在此代码中添加一个检查,以查找短信是否来自所需/所需数字
答案 0 :(得分:-1)
在BroadcastReceiver的OnReceive方法上,您可以使用下面的代码来查找发件人。
public void onReceive(Context context, Intent intent) {
//---get the SMS message passed in---
Bundle bundle = intent.getExtras();
SmsMessage[] msgs = null;
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]);
String sender = msgs[i].getOriginatingAddress();
// Your logic here to find the match
}
}