1

是否有可能截获来自某个号码的短信并将其定向到 iPhone/Android 上的某个应用程序,在那里进行处理?谢谢。

4

5 回答 5

1

In Android, what you can do is register a BroadcastReceiver to be notified that an SMS has been received, mark the message as read in the SMS Content Provider and then delete that specific message from the content provider. This will prevent any other applications from being able to read the message once you have deleted it and no notifications will be shown in the notification space. That said, I have no idea what will happen to the applications that receive the Intent indicating that a message has been received but then cannot access it in the database. This could result in unpredictable behavior as a result of a number of race conditions.

于 2010-08-22T20:31:44.620 回答
1

是的。在Android中是可能的。我正在开发的应用程序中执行此操作。你需要做的是:

public class SMSService extends BroadcastReceiver {
public static final String SMS_RECEIVED = "android.provider.Telephony.SMS_RECEIVED";
private String phoneNumber;
private String sms;
private Context context;

@Override
public void onReceive(Context context, Intent intent) {
    this.context = context;
    if (intent.getAction().equals(SMS_RECEIVED)) {
        Bundle bundle = intent.getExtras();
        SmsMessage[] msgs = null;

        if (bundle != 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]);

                // get sms message
                sms = msgs[i].getMessageBody();

                // get phone number
                phoneNumber = msgs[i].getOriginatingAddress();

                if (phoneNumber.equals("Some other phone number")){
                    // the sms will not reach normal sms app
                    abortBroadcast();

                Thread thread = new Thread(null,
                        doBackgroundThreadProcessing, "Background");
                thread.start();
                }

            }
        }
    }
}

private Runnable doBackgroundThreadProcessing = new Runnable() {
    // do whatever you want
};

重要提示: 在清单文件中,您必须使用高数字定义 SMS 优先级。我相信最大值是100。

<!-- SMS Service -->
    <service android:name=".SMSService" />
    <receiver android:name=".SMSService">
        <intent-filter android:priority="100">
            <action android:name="android.provider.Telephony.SMS_RECEIVED" />
        </intent-filter>
    </receiver>
于 2012-06-11T00:05:18.453 回答
0

For Android the answer is no. You can implement a BroadcastReceiver that is called whenever the device receives an SMS text message but cannot keep other applications (e.g. the built-in Messaging app) from receiving them too.

于 2010-08-22T20:28:32.590 回答
0

对于 Android,答案是Yes

android.provider.Telephony.SMS_RECEIVED事件是有序广播,您可以调整优先级。这意味着您的应用程序将在其他人之前收到该事件。您可以取消其余广播接收器的广播。

您可以在此处找到更多信息:stackoverflow.com/can-we-delete-an-sms-in-android-before-it-reaches-the-inbox/

于 2011-04-27T19:58:04.883 回答
0

在 Android 中,一旦您在应用程序中收到 SMS 消息,您可以使用 Intent 对象将消息的详细信息传递给另一个活动/应用程序以进行进一步处理。如果您需要将消息传递给您自己的应用程序,请使用 sendBroadcast() 方法广播 Intent 对象。在您的活动中,您只需要使用 registerReceiver() 方法来收听广播。

希望能帮助到你!李伟明

于 2011-05-15T02:42:45.970 回答