0

可能重复:
我们可以在 Android 中的 SMS 到达收件箱之前删除它吗?

我已经成功运行了接收短信代码。我无法确定的是一种方法(或者如果可能的话)来处理从我的应用程序中的特定电话号码发送的消息,而不会让用户看到它们。从其他电话号码发送的所有其他 SMS 将由正常的 Android SMS 处理处理。即,来自选定号码的 SMS 不应该对电话用户可见,而其余的应该。有什么建议么?

这是 SMSReceiver 代码(直接取自 Wei-Meng Lee 的书):

public class SMSReceiver extends BroadcastReceiver {
    @Override
        public void onReceive(Context context, Intent intent) {
            //get the received SMS message
        Bundle bundle = intent.getExtras();
            SmsMessage[] msgs = null;
            String str = "";
            if (bundle != null) {
                // retrieve 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]);
                    str += "SMS from " + msgs[i].getOriginatingAddress();
                    str += "\nMessage Text:\n";
                    str += msgs[i].getMessageBody().toString();
                    str += "\nLength="+msgs[i].getMessageBody().toString().length()+"\n";
                }  // [END FOR]
            // display the new SMS message
            Toast.makeText(context, str, Toast.LENGTH_SHORT).show();            
            // send a broadcast intent to update the SMS received in the activity
            Intent broadcastIntent = new Intent();
            broadcastIntent.setAction("SMS_RECEIVED_ACTION");
            broadcastIntent.putExtra("sms", str);
            context.sendBroadcast(broadcastIntent);
        }  // [END IF]
    }  // [END onReceive]
}  // [END SMSReceiver]
4

1 回答 1

1

well if you put an if before you start concatenating str, you can check the originating address, and compare it to your blacklist of addresses, if its on the list, then simply use the continue to skip the concatenations

于 2012-10-12T05:44:57.210 回答