iPhone/Android SMS 拦截并重定向到应用程序

发布于 2024-09-15 20:16:42 字数 62 浏览 8 评论 0原文

是否可以拦截来自特定号码的短信并将其定向到 iPhone/Android 上的特定应用程序并进行处理? 谢谢。

Is it possible to intercept an SMS coming from a certain number and direct it to a certain application on the iPhone/Android where it will be processed?
Thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

橙味迷妹 2024-09-22 20:16:42

在 Android 中,您可以做的是注册一个 BroadcastReceiver 来接收 SMS 已收到的通知,在 SMS 内容提供程序中将该消息标记为已读,然后从内容提供程序中删除该特定消息。一旦您删除该消息,这将阻止任何其他应用程序读取该消息,并且通知空间中不会显示任何通知。也就是说,我不知道接收 Intent 的应用程序会发生什么情况,表明已收到消息,但无法在数据库中访问该消息。由于许多竞争条件,这可能会导致不可预测的行为。

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.

只有影子陪我不离不弃 2024-09-22 20:16:42

是的。在 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
};

重要:
在清单文件中,您必须使用较高的数字定义短信优先级。我相信最大值是 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>

Yes. It is possible in Android. I'm doing it in an app I'm developing.
What you need to do is:

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
};

IMPORTANT:
In manifest file you have to define SMS priority with an high number. I believe the max is 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>
掩饰不了的爱 2024-09-22 20:16:42

对于 Android 来说,答案是否定的。您可以实现 BroadcastReceiver ,它是每当设备收到 SMS 文本消息但无法阻止其他应用程序(例如内置消息应用程序)也接收它们时调用。

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.

醉城メ夜风 2024-09-22 20:16:42

对于 Android,答案是

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

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

For Android the answer is Yes.

android.provider.Telephony.SMS_RECEIVED event is an ordered broadcast and you can tune the priority. This means your application will receive the event before everyone else. And you can cancel Broadcast for the rest of Broadcast Receivers.

You can find more information here: stackoverflow.com/can-we-delete-an-sms-in-android-before-it-reaches-the-inbox/

蝶…霜飞 2024-09-22 20:16:42

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

希望有帮助!
李伟猛

In Android, once you received an SMS message in your application, you can use an Intent object to pass the details of the message to another activity/application for further processing. If you need to pass the message to your own application, use the sendBroadcast() method to broadcast the Intent object. In your activity, you would just need to use the registerReceiver() method to listen for the broadcast.

Hope it helps!
Wei-Meng Lee

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文