千里冰封
          JAVA 濃香四溢
          posts - 151,comments - 2801,trackbacks - 0
          <2007年9月>
          2627282930311
          2345678
          9101112131415
          16171819202122
          23242526272829
          30123456

          盡管千里冰封
          依然擁有晴空

           

          留言簿(204)

          隨筆分類(197)

          隨筆檔案(189)

          文章檔案(2)

          友情鏈接

          搜索

          •  

          積分與排名

          • 積分 - 964340
          • 排名 - 35

          最新隨筆

          最新評論

          閱讀排行榜

          評論排行榜

          我們在開發J2ME的時候,都需要知道手機到底支持JAVA到哪種程度,比如CLDC1.0還是CLDC1.1對于簡表的支持是MIDP1.0還是MIDP2.0或者是最新的MIDP2.1.
          如果有一個程序它在手機上一運行就知道這些配置的話,在某種程度上也方便了開發,其實要實現這個一點都不難,下面就是我寫的用于檢測手機的一些參數.程序里面只檢測了一部份,大家可以根據需要加上自己需要知道的內容.

          首先是一個MIDlet,這是不能少的
          /*
           * Main.java
           * 
           * Created on 2007-9-20, 15:08:53
           * 
           * To change this template, choose Tools | Templates
           * and open the template in the editor.
           
          */

          package com.hadeslee.phone;

          import javax.microedition.midlet.*;
          import javax.microedition.lcdui.*;

          /**
           * 
          @author hadeslee
           
          */
          public class Main extends MIDlet {
              
          private InfoForm info;
              
          public Main(){
                  initOther();
              }
              
          public Display getDisplay(){
                  
          return Display.getDisplay(this);
              }
              
          //初始化一些東西
              private void initOther(){
                  info
          =new InfoForm(this);
              }
              
          public void startApp() {
                  getDisplay().setCurrent(info);
              }

              
          public void pauseApp() {
              }

              
          public void destroyApp(boolean unconditional) {
                  
              }
          }

          然后是包含了信息的一個Form
          /*
           * InfoForm.java
           *
           * Created on 2007-9-20, 15:10:02
           *
           * To change this template, choose Tools | Templates
           * and open the template in the editor.
           
          */

          package com.hadeslee.phone;

          import javax.microedition.lcdui.Alert;
          import javax.microedition.lcdui.AlertType;
          import javax.microedition.lcdui.Command;
          import javax.microedition.lcdui.CommandListener;
          import javax.microedition.lcdui.Displayable;
          import javax.microedition.lcdui.Form;
          import javax.microedition.lcdui.StringItem;
          import javax.microedition.lcdui.Ticker;

          /**
           *
           * 
          @author hadeslee
           
          */
          public class InfoForm extends Form implements CommandListener {
              
          private Main main;
              
          private Command about;
              
          private Command exit;

              
          public InfoForm(Main main) {
                  
          super("配置表");
                  
          this.main=main;
                  initOther();
              }

              
          //初始化其它
              private void initOther() {
                  about 
          = new Command("關于", Command.OK, 1);
                  exit 
          = new Command("退出", Command.EXIT, 1);
                  
          this.addCommand(about);
                  
          this.addCommand(exit);
                  
          this.setCommandListener(this);
                  
          this.setTicker(new Ticker("手機JAVA平臺參數查看"));
                  initStringItem();
              }

              
          //初始化字符串項
              private void initStringItem() {
                  String[] keys 
          = {"手機平臺""手機編碼""配置""簡表""地區""主機名"};
                  String[] values 
          = {"microedition.platform""microedition.encoding""microedition.configuration""microedition.profiles""microedition.locale""microedition.hostname"};
                  
          for (int i = 0; i < keys.length; i++) {
                      StringItem item 
          = new StringItem(keys[i], System.getProperty(values[i]));
                      
          this.append(item);
                  }
              }

              
          public void commandAction(Command c, Displayable d) {
                  
          if (c == about) {
                      main.getDisplay().setCurrent(
          new Alert("關于\n",
                              
          "查看手機的一些JAVA配置\n作者:千里冰封",null,AlertType.INFO), this);
                  } 
          else if (c == exit) {
                      main.notifyDestroyed();
                      main.destroyApp(
          true);
                  }
              }
          }

          在這里我只列舉出來了"microedition.platform", "microedition.encoding", "microedition.configuration", "microedition.profiles", "microedition.locale", "microedition.hostname"的信息,其實還有很多別的信息是可以知道的,下面是所有可查詢的信息列表:
          JSR Property Name
          Default Value¹
          30 microedition.platform null
            microedition.encoding ISO8859_1
            microedition.configuration CLDC-1.0
            microedition.profiles null
          37 microedition.locale null
            microedition.profiles MIDP-1.0
          75 microedition.io.file.FileConnection.version 1.0
            file.separator (impl-dep)
            microedition.pim.version 1.0
          118 microedition.locale null
            microedition.profiles MIDP-2.0
            microedition.commports (impl-dep)
            microedition.hostname (impl-dep)
          120 wireless.messaging.sms.smsc (impl-dep)
          139 microedition.platform (impl-dep)
            microedition.encoding ISO8859-1
            microedition.configuration CLDC-1.1
            microedition.profiles (impl-dep)
          177 microedition.smartcardslots (impl-dep)
          179 microedition.location.version 1.0
          180 microedition.sip.version 1.0
          184 microedition.m3g.version 1.0
          185 microedition.jtwi.version 1.0
          195 microedition.locale (impl-dep)
            microedition.profiles IMP-1.0
          205 wireless.messaging.sms.smsc (impl-dep)
          205 wireless.messaging.mms.mmsc (impl-dep)

          不能保證以上都有效,因為手機支持度不一樣,從JSR30到JSR205都有不同的參數可以讓我們知道.
          另外我們也可以通過MIDlet的getAppProperty(String key)來得到我們定義在JAD文件里面的一些參數,這樣就便于我們發布程序了.

          下面是以上例子的NetBeans工程文件,點擊下載.  如果想直接能運行的話,可以把dist目錄下面的兩個文件拷到手機上,就可以運行了,運行環境是最低的MIDP1.0和CLDC1.0


          盡管千里冰封
          依然擁有晴空

          你我共同品味JAVA的濃香.
          posted on 2007-09-20 16:19 千里冰封 閱讀(1193) 評論(3)  編輯  收藏 所屬分類: JAVAME

          FeedBack:
          # re: 查看手機對JAVA的支持信息
          2007-09-20 16:56 | teasp
          感覺你懂的好多啊,我現在還在入門中。。。  回復  更多評論
            
          # re: 查看手機對JAVA的支持信息
          2008-05-04 11:23 | xiaoyou
          thx..I take it.  回復  更多評論
            
          # re: 查看手機對JAVA的支持信息
          2008-08-11 00:33 | J2ME愛好者
          我自己建立一個J2ME工程,修改了你代碼,在我的手機A1200E上運行時包ClassFormatError:8的錯誤.我在extends MIDlet時destroyApp(boolean arg0)和startApp()會自己拋出MIDletStateChangeException異常,而我看你的代碼卻沒有,請問與這個有關嗎?  回復  更多評論
            
          主站蜘蛛池模板: 隆林| 宝丰县| 克什克腾旗| 丰顺县| 泊头市| 台北市| 建湖县| 云霄县| 石林| 南京市| 扎囊县| 陇南市| 临海市| 靖西县| 华坪县| 五寨县| 开原市| 山阴县| 张家川| 永康市| 法库县| 阿鲁科尔沁旗| 望江县| 阜宁县| 那曲县| 澄江县| 蒙山县| 泰来县| 水富县| 厦门市| 南开区| 青州市| 邓州市| 息烽县| 清丰县| 祥云县| 凌海市| 郴州市| 白朗县| 镶黄旗| 锡林浩特市|