package com.webtechwireless.mobile.personallocator.communication;
import net.rim.device.api.system.*;
import javax.microedition.io.*;
import com.webtechwireless.mobile.personallocator.utils.TaskTimer;
import java.io.*;
import java.util.TimerTask;
import javax.wireless.messaging.*;
public class MDTApis implements MDTInterface {
// private static long PL_ID = 0x33abf322367f9119L;
// private static String SMSURL= "sms://:";
private static String SMS_URL = "sms://:3737";
private static String PL_APP = "com.webtechwireless.mobile.personallocator.PersonalLocator";
private static final int DRIVER_LOGIN = 1;
private static final int DRIVER_LOGOFF = 2;
private final MessageCommunicator messageCommunicator;
private String[] connections;
private MessageConnection smsConn;
private SMSTimer timer;
public MDTApis(MessageCommunicator messageCommunicator) {
this.messageCommunicator = messageCommunicator;
registerSMS();
}// MDTApis
private void registerSMS() {
connections = PushRegistry.listConnections(false);
if (connections.length == 0) {
try {
// dconn = (UDPDatagramConnection)
// Connector.open("datagram://");
// String dport = "datagram://:" + dconn.getLocalPort();
// Register the port so the MIDlet will wake up, if messages
// are posted after the MIDlet exits.
PushRegistry.registerConnection(SMS_URL, PL_APP, "*");
connections = PushRegistry.listConnections(false);
if (connections == null)
return;
final int size = connections.length;
for (int i = connections.length - 1; i >= 0; --i) {
if (connections[i].equals(SMS_URL)){
smsConn = (MessageConnection) Connector
.open(connections[i]);
}
}
} catch (ConnectionNotFoundException e) {
System.out.println("ConnectionNotfoundException");
return;
} catch (IOException ioe) {
System.out.println("IOException");
return;
} catch (ClassNotFoundException cnfe) {
System.out.println("Class not found Exceptione");
return;
}
catch (Exception e) {
System.out.println("Exception");
return;
}
}
timer = new SMSTimer();
timer.start();
}
private void getSMS() {
String[] connectionsWithData = PushRegistry.listConnections(true);
// Test all connections to locate the one matching "sms://5678".
for (int i = connectionsWithData.length - 1; i >= 0; --i) {
if (connectionsWithData[i].equals(SMS_URL)) {
fetchData(SMS_URL);
}
}
}
private void fetchData(String connection) {
try {
// Open the connection.
Connection c = Connector.open(connection);
if (c instanceof MessageConnection) {
// Open a MessageConnection
MessageConnection mc = (MessageConnection) c;
TextMessage txtMsg = (TextMessage) mc.receive();
System.out.println("Received: " + txtMsg.ToString() + ", type="
+ txtMsg.getMessageType());
// getPayloadText());
}
} catch (IOException e) {
System.out.println("IOException");
}
}
private class SMSTimer extends TaskTimer {
private boolean isTimerStart = false;
public void start() {
try {
super.start(2, 2);
isTimerStart = true;
} catch (IllegalStateException ise) {
System.out.println("TravelStartTimer.IllegalState Exception");
}
}
public void stop() {
super.stop();
isTimerStart = false;
}
public TimerTask getTask() {
final TimerTask saveTask = new TimerTask() {
public void run() {
getSMS();
}
};
return saveTask;
}// run()
public boolean isTimerStart() {
return isTimerStart;
}
}// eof TravelStartTimer
public void close() {
try {
if (smsConn != null) {
smsConn.close();
smsConn = null;
}
} catch (Exception e) {
}
}
public void sendDriverLogin(String driverId) {
sendDriverLogMessage(driverId, DRIVER_LOGIN);
}
public void sendDriverLogOff(String driverId) {
sendDriverLogMessage(driverId, DRIVER_LOGOFF);
}
private void sendDriverLogMessage(String driverId, int messageType) {
String extension = "";
switch (messageType) {
case DRIVER_LOGIN:
extension = "fwd=yes appid=* log=-1," + driverId
+ ",Login msg=s:Login柒:,,,,";
break;
case DRIVER_LOGOFF:
extension = "fwd=yes appid=* log=-1," + driverId
+ ",Logout msg=s:Logout柒:,,,,";
break;
}
messageCommunicator.sendLocationRecord(
ReasonCode.REASON_CODE_DRIVER_LOG, extension);
}
}// class MDTApis
SMS.rar_blackberry_java sms_send SMS in j2me_sms blackberry_手机 短
版权申诉
200 浏览量
2022-09-24
13:17:04
上传
评论
收藏 3KB RAR 举报
局外狗
- 粉丝: 64
- 资源: 1万+
最新资源
- 5uonly.apk
- 2023-04-06-项目笔记 - 第一百十九阶段 - 4.4.2.117全局变量的作用域-117 -2024.04.30
- 2023-04-06-项目笔记 - 第一百十九阶段 - 4.4.2.117全局变量的作用域-117 -2024.04.30
- 前端开发技术实验报告:内含4四实验&实验报告
- Highlight Plus v20.0.1
- 林周瑜-论文.docx
- 基于MIC+NE555光敏电阻的声光控电路Multisim仿真原理图
- 基于JSP毕业设计-基于WEB操作系统课程教学网站的设计与实现(源代码+论文).zip
- 基于LM324和LM386的音响放大器Multisim仿真+PCB电路原理图
- Python机器学习与数据挖掘环境配置与库验证
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈