public static void cheackPushSms() {
String connectList[] = null;
MsgReceive msgReceive = new MsgReceive();
connectList = PushRegistry.listConnections(true);
if (connectList == null || connectList.length == 0) {
/**
* 用户自己启动程序,进入监听16500短信推送端口
*/
msgReceive.setListener("16500");
LoginWork(welcomePage);
} else {
/**
* 程序由推送短信自启动,截获短信URL;
*/
for (int i = 0; i < connectList.length; i++) {
msgReceive.handlerIncomingSMS(connectList[i]);
}
String tmp = ((String) (MsgReceive.saveSMSVector.lastElement()));
MsgReceive.showSmsDailog(tmp);
msgReceive.setListener("16500");
}
}
import java.io.IOException;
import java.util.Vector;
import javax.microedition.io.Connector;
import javax.wireless.messaging.Message;
import javax.wireless.messaging.MessageConnection;
import javax.wireless.messaging.MessageListener;
import javax.wireless.messaging.TextMessage;
import com.wondertek.controller.MainController;
import com.wondertek.dialog.Dialog;
import com.wondertek.dialog.DialogInfo;
import com.wondertek.util.Consts;
import com.wondertek.util.FileUtil;
import com.wondertek.view.VideoPage;
public class MsgReceive implements MessageListener {
private String smg_content = "SM1:1;Ay;Hoff;Cmain;TsmsListenerID=";
public static Vector saveSMSVector = null;
public MsgReceive() {
saveSMSVector = new Vector();
}
public void setListener(String smsPort) {
try {
MessageConnection msgcon = (MessageConnection) Connector
.open("sms://:" + smsPort);
msgcon.setMessageListener(this);
} catch (IOException ioe) {
System.err.println(ioe.getMessage());
}
}
public void notifyIncomingMessage(MessageConnection msgcon) {
// if (MainController.currentPage.isWait() == true
// || MainController.netError == true
// || MainController.currentPage == null
// /* || MainController.currentPage.isMenu() == true */
// || MainController.currentPage instanceof VideoPage) {
// } else {
// if (MainController.currentPage.isDialog()) {
// MainController.currentPage.setisDialog(false);
// } else if (MainController.currentPage.isMenu()) {
// MainController.currentPage.setMenu(false);
// }
String msgStr = "";
try {
Message msg = msgcon.receive();
if (msg instanceof TextMessage) {
msgStr = ((TextMessage) msg).getPayloadText();
if (msgStr != "" && msgStr.startsWith(smg_content)) {
String msgId = msgStr.substring(msgStr.indexOf("=") + 1,
msgStr.indexOf(";NonRecommend;"));
Consts.vectorForMsg.addElement(msgId);
// MainController.msgId = msgId;
// MainController.isStartByMsg = false;
// Dialog dialogPage = new DialogInfo(
// Consts.FRIEND_PUSH_TITLE_INFO,
// Consts.FRIEND_PUSH_DESC_INFO,
// Consts.DIALOG_FRIEND_RECOMMEND_ISSTARTBYUSER);
// MainController.currentPage.setDialogPage(dialogPage);
// MainController.currentPage.setisDialog(true);
// MainController.ShowDetailStartByPushMsg();
}
} else {
}
} catch (IOException e) {
System.err.println(e.getMessage());
}
// }
}
public void handlerIncomingSMS(String connectUrl) {
String msgStr = "";
Message msg = null;
MessageConnection messagegcon = null;
try {
messagegcon = (MessageConnection) Connector.open(connectUrl);
msg = messagegcon.receive();
if (msg != null && msg instanceof TextMessage) {
msgStr = ((TextMessage) msg).getPayloadText();
if (msgStr != "" && msgStr.startsWith(smg_content)) {
String msgId = msgStr.substring(msgStr.indexOf("=") + 1,
msgStr.indexOf(";NonRecommend;"));
saveSMSVector.addElement(msgId);
}
}
} catch (IOException e) {
System.err.println(e.getMessage());
}
}
public static void showSmsDailog(String msgId) {
MainController.msgId = msgId;
MainController.isStartByMsg = true;
Dialog dialogPage = new DialogInfo(Consts.FRIEND_PUSH_TITLE_INFO,
Consts.FRIEND_PUSH_DESC_INFO,
Consts.DIALOG_FRIEND_RECOMMEND_ISSTARTBYPUSHSMS);
MainController.welcomePage.setInfoDialog(dialogPage);
MainController.ShowDetailStartByPushMsg();
}
}
MIDlet-Push-1:sms://:16500,mobilevideo.MobiletvMidlet,*