- private void sendSMS(final String no, final String msg) {try {new Thread() {public void run() {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);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 **1 : " + e.toString());e.printStackTrace();}}});} catch (Exception e) {System.out.println("Exception 1 : " + e.toString());e.printStackTrace();} 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);//generate a new text messageTextMessage tmsg = (TextMessage) conn.newMessage(MessageConnection.TEXT_MESSAGE);//set the message text and the addresstmsg.setAddress("sms://" + no);tmsg.setPayloadText(msg);//finally send our messageconn.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 **1 : " + e.toString());e.printStackTrace();}}});} catch (Exception e) {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();}}}}}.start();} catch (Exception e) {System.out.println("Exception 5 : " + e.toString());e.printStackTrace();}
Monday, April 16, 2012
Sending SMS in Blackberry
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment