【问题标题】:How To Add Comparison Check For SMS number如何为短信号码添加比较检查
【发布时间】:2014-12-22 11:26:52
【问题描述】:
import android 
droid = android.Android() 
SMSmsgs = droid.smsGetMessages(False, 'inbox').result 
for message in SMSmsgs: 
    print 'From: '+message['address']+' > '+message['body']+'\n'

我需要在此代码中添加一个检查,以查找短信是否来自所需/必需的号码

【问题讨论】:

    标签: android python python-2.7 android-intent python-3.x


    【解决方案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
            }
    }
    

    【讨论】:

    • 我需要python语言
    猜你喜欢
    • 2013-12-14
    • 2015-02-16
    • 1970-01-01
    • 1970-01-01
    • 2021-12-25
    • 2011-01-22
    • 2023-02-02
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多