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 閱讀(350) 評論(0)  編輯  收藏 所屬分類: Tips, Tricks, Hints & Code

          主站蜘蛛池模板: 双辽市| 华蓥市| 肥西县| 巴青县| 容城县| 会东县| 五原县| 明溪县| 聂荣县| 周至县| 阿城市| 栾城县| 大安市| 新绛县| 渑池县| 平湖市| 龙口市| 松江区| 葫芦岛市| 万全县| 屏边| 榕江县| 濮阳县| 南平市| 维西| 洪雅县| 通化市| 潼关县| 大冶市| 玉龙| 同江市| 阜康市| 嘉鱼县| 铜川市| 射阳县| 马山县| 凉山| 正镶白旗| 休宁县| 阜阳市| 泰兴市|