简体   繁体   English

拦截传入的短信

[英]Intercept incoming SMS

I would like to know what are the options for intercepting an SMS. 我想知道拦截短信的方法有哪些。 I want to be able to launch some code to handle the SMS when it is received. 我希望能够在收到SMS时启动一些代码来处理SMS。 Any advise on whether this is technically possible and what options I have if there is more than one way, would be greatly appreciated. 任何关于这在技术上是否可行以及如果有不止一种方法的情况下我有什么选择的建议,将不胜感激。

Thanks Paul 谢谢保罗

Since you have so many tags, it's hard to tell which OS you're actually developing for. 由于标签太多,因此很难说出您实际在开发哪个操作系统。 On the iPhone, you cannot "snoop in" on SMS messages without the help of a patched Kernel (jailbreak). 在iPhone上,没有补丁内核(越狱)的帮助,您就无法“窥探” SMS消息。

I can speak for Symbian C++ only. 我只能代表Symbian C ++。 And good news - it's possible. 好消息-这是可能的。
You can use this code example if you want to be notified of all changes in the inbox folder: http://wiki.forum.nokia.com/index.php/CS001416_-_Listening_for_incoming_SMS_messages 如果希望收到收件箱文件夹中的所有更改通知,可以使用此代码示例: http : //wiki.forum.nokia.com/index.php/CS001416_-_Listening_for_incoming_SMS_messages
Or this example it you want to intercept messages sent to a particular port or only messages that match some text pattern: http://wiki.forum.nokia.com/index.php/SMS_Utilities_API 或在此示例中,您要拦截发送到特定端口的消息或仅拦截与某些文本模式匹配的消息: http : //wiki.forum.nokia.com/index.php/SMS_Utilities_API

If you don't want the intercepted message to appear in the inbox folder use the second example. 如果您不希望截获的消息出现在收件箱文件夹中,请使用第二个示例。

in blackberry you can attach message listener to specific port. 在黑莓机中,您可以将消息侦听器附加到特定端口。

try {
            final MessageConnection conn = (MessageConnection) Connector.open("sms://:"+port);
            conn.setMessageListener(new MessageListener() {

                public void notifyIncomingMessage(MessageConnection mc) {
                    Message msg;
                    try {
                        msg = conn.receive();
                    } catch (InterruptedIOException ex) {
                        ex.printStackTrace();
                    } catch (IOException ex) {
                        ex.printStackTrace();
                    }
                    String senderAddress = msg.getAddress(); // Get info from message
                    if (msg instanceof TextMessage) {
                        String msgReceived = ((TextMessage) msg).getPayloadText();
                        // Do something with the message here
                    } else if (msg instanceof BinaryMessage) {
                        byte[] msgReceived = ((BinaryMessage) msg).getPayloadData();
                        // do something with the binary message here
                    }
                }
            });

        } catch (IOException ex) {
            ex.printStackTrace();
        }

port=0 means you can listen for all default incoming sms. port = 0表示您可以监听所有默认传入的短信。

if you attach the message listener to port other than 0, message will not appear in inbox. 如果将消息侦听器附加到0以外的端口,则消息不会出现在收件箱中。 but if you failed to handle this message, it will appear in inbox. 但是如果您无法处理此消息,它将显示在收件箱中。

some restrictions are there for message listeners. 邮件侦听器有一些限制。

  1. you can't read SMS directly from inbox folder. 您无法直接从收件箱文件夹中读取SMS。
  2. only one 3rd party application can listen on one port. 只有一个第三方应用程序可以在一个端口上侦听。 eg if your application is listening on port 0, no other application can listen on this port. 例如,如果您的应用程序正在侦听端口0,则其他任何应用程序都无法侦听此端口。
  3. after blackberry restart, blackberry will remove you message listener. 黑莓重新启动后,黑莓将删除您的消息侦听器。

For Windows Mobile it's quite easy to intercept SMS messages using the MessageInterceptor class . 对于Windows Mobile,使用MessageInterceptor类截取SMS消息非常容易。 MSDN even has an article covering how to use it . MSDN甚至有一篇文章介绍了如何使用它

在blakberry,您也无法监视在标准端口上运行的SMS消息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM