Look into it ~

          present
          隨筆 - 32, 文章 - 0, 評論 - 3, 引用 - 0

          導航

          <2008年8月>
          272829303112
          3456789
          10111213141516
          17181920212223
          24252627282930
          31123456

          常用鏈接

          留言簿(2)

          隨筆分類

          隨筆檔案

          搜索

          •  

          最新評論

          閱讀排行榜

          評論排行榜

          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

          主站蜘蛛池模板: 皋兰县| 周宁县| 珠海市| 甘德县| 荃湾区| 平昌县| 龙口市| 洛川县| 平阳县| 江北区| 芷江| 江山市| 丰都县| 扶风县| 呼玛县| 临沂市| 铜鼓县| 理塘县| 出国| 盘锦市| 桐柏县| 定陶县| 克山县| 乐亭县| 台北市| 蓝山县| 永康市| 鸡东县| 拉萨市| 凤阳县| 玉田县| 临澧县| 绥化市| 永顺县| 霍州市| 淮滨县| 潼关县| 财经| 阳原县| 蓬溪县| 旬邑县|