Intercept incoming SMS

和自甴很熟 提交于 2019-12-11 03:53:38

问题


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. 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


回答1:


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).




回答2:


I can speak for Symbian C++ only. 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
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

If you don't want the intercepted message to appear in the inbox folder use the second example.




回答3:


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.

if you attach the message listener to port other than 0, message will not appear in inbox. 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.
  2. only one 3rd party application can listen on one port. e.g. if your application is listening on port 0, no other application can listen on this port.
  3. after blackberry restart, blackberry will remove you message listener.



回答4:


For Windows Mobile it's quite easy to intercept SMS messages using the MessageInterceptor class. MSDN even has an article covering how to use it.




回答5:


At blakberry you also can not spy on SMS messages, which run on standard port.



来源:https://stackoverflow.com/questions/3293685/intercept-incoming-sms

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!