开机就能自动启动MIDlet

开机自启动功能是通过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);
}

原文地址:http://developer.sonyericsson.com/site/global/techsupport/tipstrickscode/java/p_autostarting_jp7midlets.jsp

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值