j2meblog

symbian

开机就能自动启动MIDlet J2ME push实现

J2ME开机自启动功能是通过Push注册来完成的,因此可以使用两种方式来注册。第一种通过在jad文件注明PUSH注册的方式即可,如下。

//MIDlet-Push-: , ,
MIDlet-Push-1: autostart://:, AutoStartStatic, *

请注意URL的写法是autostart://:

如果想动态注册,可以通过下面的方法。

//Registers the pushRegistry
public void Register(){
// List of registered push connections.
String connections[];
// Check to see if the connection has been registered.
// This is a dynamic connection allocated on first
// time execution of this MIDlet.
connections = PushRegistry.listConnections(false);
if (connections.length == 0) {
try {
//Register so the MIDlet will wake up when phone is started.
PushRegistry.registerConnection("autostart://:", "AutoStartDyn", "*");
sDisplayString = "MIDlet is registered";
} catch (Exception ex) {
System.out.println("Exception: " + ex);
sDisplayString = "Fail: " + ex;
}
} else {
sDisplayString = "Already registered";
}
displayForm.deleteAll();
displayForm.append(sDisplayString);
}

//Unregisters the pushRegistry
public void Unregister(){
if (PushRegistry.unregisterConnection("autostart://:")){
System.out.println("The pushRegistry is unregistered");
sDisplayString = "MIDlet is unregistered.";
}else{
System.out.println("There is no pushRegistry to unregister");
sDisplayString = "No MIDlet to unregister or failed to unregister";
}
displayForm.deleteAll();
displayForm.append(sDisplayString);
}

由于手头没有SonyEricsson JP7平台的手机,因此没有办法测试开机自动启动功能。有条件的可以自己测试一下。

http://www.j2mehome.com/j2me/jinjie/9268.html

posted on 2009-08-13 22:25 j2meer 阅读(291) 评论(0)  编辑 收藏 引用

只有注册用户登录后才能发表评论。