在索尼爱立信JP7平台上自动启动MIDlet

王朝other·作者佚名  2008-05-31
窄屏简体版  字體: |||超大  

开机就能自动启动MIDlet一直是J2ME开发者的梦想,这一梦想在索尼爱立信的JP7平台上实现了。不过需要注意的是早期的几款机型不支持,比如K790等。具体请参考索尼爱立信的手册。

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

//MIDlet-Push-<n>: <ConnectionURL>, <MIDletClassName>, <AllowedSender>

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://developer.sonyericsson.com/site/global/techsupport/

tipstrickscode/Java/p_autostarting_jp7midlets.jsp

进入讨论组讨论。

(出处:http://www.knowsky.com)

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
 
 
© 2005- 王朝網路 版權所有 導航