如何在Blackberry中以编程方式发送SMS [英] How to send SMS Programmatically in Blackberry

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

问题描述

如何在BlackBerry中以编程方式发送SMS?

How to send SMS programmatically in BlackBerry?

我在某处阅读,我需要服务器端以及用于发送SMS的客户端代码.是真的吗为了将消息从一台设备发送到另一台设备或从仿真器发送到设备,我真的需要服务器端以及客户端代码吗?

And I read somewhere, I need server side as well as client side code for sending 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?

我在客户端的某个地方找到了此代码,但没有得到输出.

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

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();
}

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

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