Can any one help me to write application to send and recieve sms in blackberry.If u can provide me some code snippet .
+7
A:
To send an sms:
import net.rim.device.api.io.*;
import net.rim.device.api.system.*;
import javax.microedition.io.*;
import java.util.*;
import java.io.*;
public class SendSms extends Application
{
private static final int MAX_PHONE_NUMBER_LENGTH = 32;
private String addr = "15191112222";
private String msg = "This is a test message.";
private DatagramConnection _dc = null;
private static String _openString = "sms://";
public static void main(String[] args)
{
new SendSms().enterEventDispatcher();
}
public SendSms()
{
try {
_dc = (DatagramConnection)Connector.open(_openString);
byte[] data = msg.getBytes();
Datagram d = _dc.newDatagram(_dc.getMaximumLength());
d.setAddress("//" + addr);
_dc.send(d);
} catch ( IOException e) {}
System.exit(0);
}
}
To recieve an sms:
import net.rim.device.api.io.*;
import net.rim.device.api.system.*;
import javax.microedition.io.*;
import java.util.*;
import java.io.*;
public class ReceiveSms extends Application {
private ListeningThread _listener;
public static void main(String[] args)
{
new ReceiveSms().enterEventDispatcher();
}
ReceiveSms() {
_listener = new ListeningThread();
_listener.start();
}
private class ListeningThread extends Thread
{
private boolean _stop = false;
private DatagramConnection _dc;
public synchronized void stop()
{
_stop = true;
try {
_dc.close();
} catch (IOException e) {
System.err.println(e.toString());
}
}
public void run()
{
try {
_dc = (DatagramConnection)Connector.open("sms://");
for(;;)
{
if ( _stop ) {
return;
}
Datagram d = _dc.newDatagram(_dc.getMaximumLength());
_dc.receive(d);
String address = new String(d.getData());
String msg = new String(d.getData());
System.out.println("Message received: " + msg);
System.out.println("From: " + address);
System.exit(0);
}
} catch (IOException e) {
System.err.println(e.toString());
}
}
}
}
Ashraf Bashir
2009-12-28 12:16:24
Hi Ashraf thanks for ur help can u provide code to update the received msg in the screen because i tried myself but i could not able to achive.
Kumar
2009-12-28 14:15:54
harami why dont you mark his answer up at least
I__
2009-12-28 14:29:07
What do you mean by "updating the received messsage" ? Can you explain this in more details ?
Ashraf Bashir
2009-12-28 15:10:05
Hey Ashraf i would like to display the recieved sms in the screen.How to do this?
Kumar
2009-12-29 04:03:06
You can replace the "System.out.println" and "System.err.println" functions with, for example, the creation of a Dialog object (see http://www.blackberry.com/developers/docs/4.5.0api/net/rim/device/api/ui/component/Dialog.html), or you can show the message in a simple LabelField (see http://www.blackberry.com/developers/docs/4.5.0api/net/rim/device/api/ui/component/LabelField.html) you have many alternatives for the UI.
Ashraf Bashir
2009-12-29 08:18:25
thanks ashraf..
Kumar
2009-12-30 03:32:45
A:
Hi guys, Im trying to write some code to connect my pc with my blackberry via usb data cable to sending sms... but i can't find the way to do this connection, i mean: how do i open a connection in pc windows application with the blackberry? ... does the blackberry use or accept at commands? ...
please, need this help.
regards,
Gustavo Sierra Ecuador
Gustavo Sierra
2010-07-28 14:17:14