如何编程方式发送短信的黑莓 [英] How to send SMS Programatically in Blackberry

查看:230
本文介绍了如何编程方式发送短信的黑莓的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想发短信编程黑莓。

请给我建议,如果您有任何想法。

和我读的地方,我需要服务器端和客户端code为sendind短信。是真的吗?发送1设备的消息,或者在不同模拟器设备,我真的需要服务器端和客户端code?请指导me..Thanks提前..

我发现这个code某处客户端,但我没有得到output..Please帮助我..

 私人无效sendSMS(电话字符串,字符串消息)抛出的RuntimeException,ServicesManagerException,IOException异常
    {
        // TODO自动生成方法存根        的System.out.println(在发送短信功能);
        MessageConnection康恩=
            (MessageConnection)Connector.open(短信:// + 919099087960);
        BinaryMessage msgOut =(BinaryMessage)conn.newMessage(MessageConnection.BINARY_MESSAGE);
        msgOut.setPayloadData(我的二进制负载.getBytes(UTF-8));
        conn.send(msgOut);    }


解决方案

您不需要任何服务器端code。检查以下code。

 静态弦乐味精=海;
尝试{
    新的Thread(){
        公共无效的run(){
            如果(RadioInfo.getNetworkType()== RadioInfo.NETWORK_CDMA){
                了DatagramConnection直流=无效;
                尝试{
                    DC =(了DatagramConnection)Connector.open(短信:// + 919099087960);
                    字节[]数据= msg.getBytes();
                    数据报DG = dc.newDatagram(dc.getMaximumLength());
                    dg.setData(数据,0,data.length);
                    dc.send(克);
                    UiApplication.getUiApplication()的invokeLater(Runnable的新(){
                        公共无效的run(){
                            尝试{
                                的System.out.println(消息发送成功:数据报);
                                Dialog.alert(消息发送成功);
                            }赶上(例外五){
                                的System.out.println(异常:+ e.toString());
                                e.printStackTrace();
                            }
                        }
                    });
                }赶上(例外五){
                    的System.out.println(异常:+ e.toString());
                    e.printStackTrace();
                } {最后
                    尝试{
                        dc.close();
                        直流=无效;
                    }赶上(IOException异常五){
                        的System.out.println(异常:+ e.toString());
                        e.printStackTrace();
                    }
                }
            }其他{
                MessageConnection康恩= NULL;
                尝试{
                    康恩=(MessageConnection)Connector.open(短信:// + 919099087960);
                    //生成一个新的文本信息
                    TextMessage的TMSG =(TextMessage的)conn.newMessage(MessageConnection.TEXT_MESSAGE);
                    //设置消息文本和地址
                    tmsg.setAddress(短信:// + 919099087960);
                    tmsg.setPayloadText(MSG);
                    //最后发送我们的信息
                    conn.send(TMSG);
                    UiApplication.getUiApplication()的invokeLater(Runnable的新(){
                        公共无效的run(){
                            尝试{
                                的System.out.println(消息发送成功:TextMessage的);
                                Dialog.alert(消息发送成功:TextMessage的);
                            }赶上(例外五){
                                的System.out.println(异常:+ e.toString());
                                e.printStackTrace();
                            }
                        }
                    });
                }赶上(例外五){
                    的System.out.println(异常:+ e.toString());
                    e.printStackTrace();
                } {最后
                    尝试{
                        conn.close();
                        康恩= NULL;
                    }赶上(IOException异常五){
                        的System.out.println(异常:+ e.toString());
                        e.printStackTrace();
                    }
                }
            }
        }
    }。开始();
}赶上(例外五){
    的System.out.println(异常:+ e.toString());
    e.printStackTrace();
}

I want to send SMS programmatically in BlackBerry.

Please suggest me if you have any idea..

And I read somewhere, I need server side as well as client side code for sendind SMS. Is it True? For sending message from 1 device to another or from Emulator to device, Do I really need server side as well as client side code? Please Guide me..Thanks in Advance..

I found this code somewhere for client side, but I am not getting output..Please Help me..

private void sendSMS(String phone, String message) throws RuntimeException, ServicesManagerException, IOException 
    {
        // TODO Auto-generated method stub

        System.out.println("in send sms function");
        MessageConnection conn =
            (MessageConnection)Connector.open("sms://+919099087960");
        BinaryMessage msgOut = (BinaryMessage) conn.newMessage(MessageConnection.BINARY_MESSAGE);
        msgOut.setPayloadData("my binary payload".getBytes("UTF-8"));
        conn.send(msgOut);

    }

解决方案

You don't need any server side code. Check following code.

static String msg="hai";
try {
    new Thread() {
        public void run() {
            if (RadioInfo.getNetworkType() == RadioInfo.NETWORK_CDMA) {
                DatagramConnection dc = null;
                try {
                    dc = (DatagramConnection) Connector.open("sms://+919099087960");
                    byte[] data = msg.getBytes();
                    Datagram dg = dc.newDatagram(dc.getMaximumLength());
                    dg.setData(data, 0, data.length);
                    dc.send(dg);
                    UiApplication.getUiApplication().invokeLater(new Runnable() {
                        public void run() {
                            try {
                                System.out.println("Message Sent Successfully : Datagram");
                                Dialog.alert("Message Sent Successfully");
                            } catch (Exception e) {
                                System.out.println("Exception  : " + e.toString());
                                e.printStackTrace();
                            }
                        }
                    });
                } catch (Exception e) {
                    System.out.println("Exception  : " + e.toString());
                    e.printStackTrace();
                } finally {
                    try {
                        dc.close();
                        dc = null;
                    } catch (IOException e) {
                        System.out.println("Exception  : " + e.toString());
                        e.printStackTrace();
                    }
                }
            } else {
                MessageConnection conn = null;
                try {
                    conn = (MessageConnection) Connector.open("sms://+919099087960");
                    //generate a new text message
                    TextMessage tmsg = (TextMessage) conn.newMessage(MessageConnection.TEXT_MESSAGE);
                    //set the message text and the address
                    tmsg.setAddress("sms://+919099087960");
                    tmsg.setPayloadText(msg);
                    //finally send our message
                    conn.send(tmsg);
                    UiApplication.getUiApplication().invokeLater(new Runnable() {
                        public void run() {
                            try {
                                System.out.println("Message Sent Successfully : TextMessage");
                                Dialog.alert("Message Sent Successfully : TextMessage");
                            } catch (Exception e) {
                                System.out.println("Exception  : " + e.toString());
                                e.printStackTrace();
                            }
                        }
                    });
                } catch (Exception e) {
                    System.out.println("Exception  : " + e.toString());
                    e.printStackTrace();
                } finally {
                    try {
                        conn.close();
                        conn = null;
                    } catch (IOException e) {
                        System.out.println("Exception  : " + e.toString());
                        e.printStackTrace();
                    }
                }
            }
        }
    }.start();
} catch (Exception e) {
    System.out.println("Exception  : " + e.toString());
    e.printStackTrace();
}

这篇关于如何编程方式发送短信的黑莓的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆