Look into it ~

          present
          隨筆 - 32, 文章 - 0, 評論 - 3, 引用 - 0
          數據加載中……

          Autostarting MIDlets in JP-7 phones using PushRegistry

          In Sony Ericsson Java Platform 7 (JP-7) phones, such as the K610 or W850, a new push functionality is introduced. PushRegistry Alarm and PushRegistry SMS are supported throughout the Java Platforms, with JP-4 adding PushRegistry CBS and now JP-7 includes PushRegistry auto start.

          Note: the auto start functionality is not supported by the first released K610 and K800 JP-7 phones. Please use the phone's upgrade service to ensure that you are using the latest firmware version.

          The auto start functionality can be set static by including it in the .jad file or it can be set dynamically in the code. Two example MIDlets are included as an example of this.

          Download the source code and examples here>>

          To enable the auto start functionality in the .jad file include the line:
          //MIDlet-Push-<n>: <ConnectionURL>, <MIDletClassName>, <AllowedSender>
          MIDlet-Push-1: autostart://:, AutoStartStatic, *


          To make the MIDlet auto start from the source code the following methods can be used to register and un-register the MIDlet.
          //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);
          }



          To find out if the MIDlet is started via pushRegistry or manually you can inspect the connections registered by pushRegistry. Below is a small example of how to handle pushRegistry autostart or manual startup.
              private void handlePushActivation() {
                  String[] connections 
          = PushRegistry.listConnections(true);
                  
          if (connections != null && connections.length > 0) {
                      
          for (int i = 0; i < connections.length; i++) {
                          
          if (connections[i].startsWith("autostart")) {
                              alert(
          "Application autostarted");
                          }
                      }
                  } 
          else {
                      alert(
          "User started the application");
                  }
              }

          posted on 2008-08-15 10:57 LukeW 閱讀(351) 評論(0)  編輯  收藏 所屬分類: Tips, Tricks, Hints & Code

          主站蜘蛛池模板: 赤壁市| 陆良县| 大丰市| 启东市| 广平县| 凤冈县| 石泉县| 卢湾区| 江门市| 石屏县| 华亭县| 怀仁县| 天台县| 临江市| 繁昌县| 武强县| 综艺| 特克斯县| 云南省| 海南省| 邛崃市| 启东市| 石景山区| 雅安市| 牡丹江市| 牙克石市| 西乌| 金坛市| 镇安县| 通化市| 汝城县| 军事| 上饶市| 白朗县| 乌海市| 双牌县| 乐山市| 册亨县| 万山特区| 易门县| 纳雍县|