从 BlackBerry Simulator 发送短信

发布于 2025-01-02 02:19:42 字数 155 浏览 0 评论 0原文

我正在开发一个 BlackBerry 应用程序,我应该在其中从 BlackBerry 设备发送短信。 由于我是黑莓的新手,几天前开始我无法继续。

任何人都可以帮助提供从 BlackBerry 设备或模拟器发送短信的代码片段吗?

提前致谢。

苏雷什。

I'm developing a BlackBerry Application where I should send Text SMS from BlackBerry Device.
As I'm new to Blackberry, started few days back I'm unable to proceed.

Can anyone Help with providing code snippets for send SMS from BlackBerry Device or Simulator?

Thanks in Advance.

Suresh.

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

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

发布评论

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

评论(2

婴鹅 2025-01-09 02:19:42
public static void sendSMS(final String no, final String msg) {
    // try {
    new Thread() {
        public void run() {

            boolean smsSuccess = false;
            if (RadioInfo.getNetworkType() == RadioInfo.NETWORK_CDMA) {


                DatagramConnection dc = null;
                try {
                    dc = (DatagramConnection) Connector.open("sms://" + no);
                    byte[] data = msg.getBytes();
                    Datagram dg = dc.newDatagram(dc.getMaximumLength());
                    dg.setData(data, 0, data.length);
                    dc.send(dg);
                    // / send successfully
                    smsSuccess = true;
                } catch (Exception e) {
                    System.out.println("Exception 1 : " + e.toString());
                    e.printStackTrace();
                    smsSuccess = false;
                } finally {
                    try {
                        dc.close();
                        dc = null;
                    } catch (IOException e) {
                        System.out.println("Exception 2 : " + e.toString());
                        e.printStackTrace();
                    }
                }
            } else {
                MessageConnection conn = null;
                try {
                    conn = (MessageConnection) Connector
                            .open("sms://" + no);
                    TextMessage tmsg = (TextMessage) conn
                            .newMessage(MessageConnection.TEXT_MESSAGE);
                    tmsg.setAddress("sms://" + no);
                    tmsg.setPayloadText(msg);
                    conn.send(tmsg);
                    smsSuccess = true;
                } catch (Exception e) {
                    smsSuccess = false;
                    System.out.println("Exception 3 : " + e.toString());
                    e.printStackTrace();
                } finally {
                    try {
                        conn.close();
                        conn = null;
                    } catch (IOException e) {
                        System.out.println("Exception 4 : " + e.toString());
                        e.printStackTrace();
                    }
                }
            }
            if(smsSuccess)
            {
                UiApplication.getUiApplication().invokeLater(new Runnable() {

                    public void run() {
                        // TODO Auto-generated method stub
                        Dialog.alert("success");
                    }
                }); 
            }else
            {
                UiApplication.getUiApplication().invokeLater(new Runnable() {

                    public void run() {
                        // TODO Auto-generated method stub
                        Dialog.alert("failure");
                    }
                }); 

            }

        }
    }.start();
} 

查看上面的代码功能....从黑莓发送短信

public static void sendSMS(final String no, final String msg) {
    // try {
    new Thread() {
        public void run() {

            boolean smsSuccess = false;
            if (RadioInfo.getNetworkType() == RadioInfo.NETWORK_CDMA) {


                DatagramConnection dc = null;
                try {
                    dc = (DatagramConnection) Connector.open("sms://" + no);
                    byte[] data = msg.getBytes();
                    Datagram dg = dc.newDatagram(dc.getMaximumLength());
                    dg.setData(data, 0, data.length);
                    dc.send(dg);
                    // / send successfully
                    smsSuccess = true;
                } catch (Exception e) {
                    System.out.println("Exception 1 : " + e.toString());
                    e.printStackTrace();
                    smsSuccess = false;
                } finally {
                    try {
                        dc.close();
                        dc = null;
                    } catch (IOException e) {
                        System.out.println("Exception 2 : " + e.toString());
                        e.printStackTrace();
                    }
                }
            } else {
                MessageConnection conn = null;
                try {
                    conn = (MessageConnection) Connector
                            .open("sms://" + no);
                    TextMessage tmsg = (TextMessage) conn
                            .newMessage(MessageConnection.TEXT_MESSAGE);
                    tmsg.setAddress("sms://" + no);
                    tmsg.setPayloadText(msg);
                    conn.send(tmsg);
                    smsSuccess = true;
                } catch (Exception e) {
                    smsSuccess = false;
                    System.out.println("Exception 3 : " + e.toString());
                    e.printStackTrace();
                } finally {
                    try {
                        conn.close();
                        conn = null;
                    } catch (IOException e) {
                        System.out.println("Exception 4 : " + e.toString());
                        e.printStackTrace();
                    }
                }
            }
            if(smsSuccess)
            {
                UiApplication.getUiApplication().invokeLater(new Runnable() {

                    public void run() {
                        // TODO Auto-generated method stub
                        Dialog.alert("success");
                    }
                }); 
            }else
            {
                UiApplication.getUiApplication().invokeLater(new Runnable() {

                    public void run() {
                        // TODO Auto-generated method stub
                        Dialog.alert("failure");
                    }
                }); 

            }

        }
    }.start();
} 

Check out the the above code function .... to send SMS from Blackberry

殊姿 2025-01-09 02:19:42

您还没有指定要使用哪种语言进行开发,但如果您使用 java 进行开发,并且使用 Eclipse 和 Blackberry Java 插件进行开发,您将在插件文件夹层次结构中找到大量示例应用程序。实际位置取决于您安装 Eclipse 的位置,但例如在我的计算机上,它们位于:C:\Program Files\Eclipse\eclipse 3.6.2 BlackBerry\plugins\net.rim.ejde.componentpack7.0.0_7.0.0。 OS7 示例的 33\components\samples\com\rim\samples\device。您安装的不同操作系统插件都会存在类似的示例。

大多数操作系统示例集中都有一个名为 smsdemo 的长期示例,它应该为您提供所需的所有代码。即使您不是使用 Java 进行开发,此示例也应该为您指明满足您的需求所需采取的路径。

You haven't specified what language you are developing in, but if you are developing in java and, if you are using Eclipse for your development with the Blackberry Java plugins, you will find a wealth of sample applications in the plugins folder hierarchy. The actual location will depend on where you have installed Eclipse, but e.g. on my machine they are at: C:\Program Files\Eclipse\eclipse 3.6.2 BlackBerry\plugins\net.rim.ejde.componentpack7.0.0_7.0.0.33\components\samples\com\rim\samples\device for the OS7 samples. Similar samples will exist for the different OS plugins you have installed.

There is a long standing sample in most OS sample sets called smsdemo which should give you all the code you need. Even if you are not developing in java, this sample should give you an indication of the path you need to take to fulfil your requirement.

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