如何写黑莓短信报名? [英] How to write SMS application in blackberry?
本文介绍了如何写黑莓短信报名?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
任何一个可以帮我写应用程序在blackberry.If发送和接收短信u能提供我一些code片段。
Can any one help me to write application to send and recieve sms in blackberry.If u can provide me some code snippet .
推荐答案
要发送短信:
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);
}
}
要收到短信:
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());
}
}
}
}
这篇关于如何写黑莓短信报名?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文