【问题标题】:Incoming sms listener on blackberry黑莓上的传入短信侦听器
【发布时间】:2013-06-26 14:18:06
【问题描述】:

我用下面的代码来通知短信。

它在两个黑莓模拟器上工作。

我已经在我的设备上安装了应用程序并从安卓设备发送短信。

短信监听器在设备上不工作。

在设备上收到传入消息。但我的应用程序没有通知听众。

有什么问题怎么解决。

需要为设备提供什么端口号

class BackgroundApplication extends Application  implements MessageListener
{  
    int i=0;
    static String suffix;
    MessageConnection _mc ;

    public BackgroundApplication() 
    {
        try {
            _mc = (MessageConnection)Connector.open("sms://:0");
            _mc.setMessageListener(this);
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } 


    }

public void notifyIncomingMessage(MessageConnection conn) {
        try {

            Message m = _mc.receive();
            String address = m.getAddress();
            String msg = null;
            if ( m instanceof TextMessage )
            {
                TextMessage tm = (TextMessage)m;
                msg = tm.getPayloadText();
            }
            else if (m instanceof BinaryMessage) {
                StringBuffer buf = new StringBuffer();
                byte[] data = ((BinaryMessage) m).getPayloadData();

                // convert Binary Data to Text
                msg = new String(data, "UTF-8");
            }
            else
                System.out.println("Invalid Message Format");
            System.out.println("Received SMS text from " + address + " : " + msg);
            showDialog("Msg: "+msg);

        } catch (Exception e) {
            // TODO: handle exception
        }
    }


    private void showDialog(String string) {


        synchronized (UiApplication.getEventLock()) 
        {
            Status.show(""+string,Bitmap.getPredefinedBitmap(Bitmap.INFORMATION), 5000,
                    Status.GLOBAL_STATUS, true, false, 1);
        }

    }

}

【问题讨论】:

  • @Signare hi 需要将端口号 0 更改为 6222?
  • wt端口号需要给吗?

标签: blackberry


【解决方案1】:

检查一下

http://supportforums.blackberry.com/t5/Java-Development/Different-ways-to-listen-for-SMS-messages/ta-p/445062

DatagramConnection _dc =
     (DatagramConnection)Connector.open("sms://");
            for(;;)
        {
               Datagram d = _dc.newDatagram(_dc.getMaximumLength());
               _dc.receive(d);
               byte[] bytes = d.getData();
               String address = d.getAddress();
               String msg = new String(bytes);
               System.out.println( "Received SMS text from " + address + " : " + msg);
         }

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多