饒榮慶 -- 您今天UCWEB了嗎?--http://www.ucweb.com

          3G 手機開發(fā)網(wǎng)

             :: 首頁 :: 聯(lián)系 :: 聚合  :: 管理
            99 Posts :: 1 Stories :: 219 Comments :: 0 Trackbacks
          原文地址

          相信做手機開發(fā)的都知道,write once debug anywhere。你向從中體驗樂趣嗎,那先來了解下手機對JSR規(guī)范的支持吧。
          下面是我從網(wǎng)絡(luò)上獲取一些的信息。
          其中一個源代碼出自http://www.javaeye.com/topic/75387
          大家可以到上面下載源代碼,然后稍微修改下,就可以提供對jsr的更多測試了。
          關(guān)于測試的方面看下面

          For instance, the property microedition.commports is present in the MIDP 2.0 specification. Its value is a comma-separated list of ports you can use to build a URL, which the Generic Connection Framework can in turn use to create a javax.microedition.io.CommConnection object.
          To query system properties use java.lang.System.getProperty(), as in:

          import java.lang.*;

          String value;
          String key = "microedition.pim.version";

          value = System.getProperty( key );
          ...



          This table lists the defined system properties, drawing them from JSRs that are in the public review, final ballot, or final state, as defined in the Java Community Process (JCP):

          J2ME Defined System Properties

          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)
          211 CHAPI-Version 1.0

          這個是e文的

          看看中文的吧

          2.3.4 MIDP應(yīng)用程序的屬性

          MIDlet可以訪問兩種運行時的屬性值:系統(tǒng)屬性和應(yīng)用程序?qū)傩浴?/font>

          1.系統(tǒng)屬性

          系統(tǒng)屬性是在CLDC(Connected Limited Device Configuration)中定義的,屬性值被寫入底層的系統(tǒng),我們可以讀取它們,但是不能修改這些屬性值。如果想讀取一個系統(tǒng)屬性值,那么可以使用System類的靜態(tài)方法System.getProperty()來讀取。有時候我們可能想讀取特定手機的系統(tǒng)信息,比如IMEI號。解決辦法就是去參考這款手機的開發(fā)指南和規(guī)范,比如,從SonyEricsson系列手機讀取IMEI號,調(diào)用方法:System.getProperty ("com. onyericsson.imei"),這時將返回手機的IMEI號碼,如IMEI 123456-00-123456-1-00。需要說明的一點是,在SonyEricsson P910上查詢IMEI號碼時,傳遞的字符串參數(shù)應(yīng)該是com.sonyericsson.IMEI(IMEI須大寫)。如果在不支持此項功能的手機上查詢IMEI號時,將什么都不返回,例如,在T610上調(diào)用。

          表2-3列舉了系統(tǒng)屬性。

          表2-3 MIDP應(yīng)用程序系統(tǒng)屬性

          JSR

          屬性名稱

          認(rèn)

          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

          依賴于底層實現(xiàn)


          microedition.pim.version

          1.0

          118

          microedition.locale

          null


          microedition.profiles

          MIDP-2.0


          microedition.commports

          依賴于底層實現(xiàn)


          microedition.hostname

          依賴于底層實現(xiàn)

          120

          wireless.messaging.sms.smsc

          依賴于底層實現(xiàn)

          139

          microedition.platform

          依賴于底層實現(xiàn)


          microedition.encoding

          ISO8859-1


          microedition.configuration

          CLDC-1.1


          microedition.profiles

          依賴于底層實現(xiàn)

          177

          microedition.smartcardslots

          依賴于底層實現(xiàn)

          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

          依賴于底層實現(xiàn)


          microedition.profiles

          IMP-1.0

          205

          wireless.messaging.sms.smsc

          依賴于底層實現(xiàn)

          205

          wireless.messaging.mms.mmsc

          依賴于底層實現(xiàn)

          2.應(yīng)用程序?qū)傩?/font>

          應(yīng)用程序?qū)傩灾凳窃趹?yīng)用程序描述符文件或者MANIFEST文件中定義的,當(dāng)我們部署應(yīng)用程序的時候可以定義應(yīng)用程序?qū)傩浴1热缦旅媸且粋€典型的JAD文件內(nèi)容。

          MIDlet-1: HttpWrapperMidlet,httpwrapper.HttpWrapperMIDlet

          MIDlet-Jar-Size: 16315

          MIDlet-Jar-URL: HttpWrapper.jar

          MIDlet-Name: HttpWrapper

          MIDlet-Vendor: Vendor

          MIDlet-Version: 1.0

          MicroEdition-Configuration: CLDC-1.0

          MicroEdition-Profile: MIDP-1.0

          Which-Locale: en

          其中Which-Locale就是應(yīng)用程序?qū)傩灾?,我們可以通過MIDlet的成員方法getAppProperty()來得到它,代碼片斷如下:

          import javax.microedition.midlet.*;

          public class MyMIDlet extends MIDlet {

          private String suiteName;

          private String which_locale;

          public MyMIDlet(){

          suiteName = getAppProperty( "MIDlet-Name" );

          which_locale = getAppProperty("Which-Locale");

          }

          //這里省略了其他代碼

          }

          屬性值對大小寫是敏感的,如果屬性值在底層系統(tǒng)、JAD文件和Manifest文件中都沒有定義的話,那么將返回Null。

          熟悉MIDP應(yīng)用程序的系統(tǒng)屬性對我們開發(fā)靈活、強大的MIDlet至關(guān)重要。可以根據(jù)系統(tǒng)屬性返回值來動態(tài)地生成應(yīng)用程序的菜單。例如,通過判斷底層系統(tǒng)是否支持MMAPI來決定應(yīng)用程序中是否要添加攝像功能。下面的例子演示了如何在MIDlet中讀取系統(tǒng)屬性。

          package com.j2medev.ch3.property;

          import javax.microedition.lcdui.*;

          import javax.microedition.midlet.*;

          public class DetectMIDlet extends MIDlet {

          private static DetectMIDlet instance = null;

          private Display display = null;

          private Displayable form = null;

          public DetectMIDlet() {

          instance = this;

          }

          protected void startApp() {

          if(display==null) {

          //首次啟動應(yīng)用程序

          display = Display.getDisplay(this);

          form = new TestForm();

          display.setCurrent(form);

          } else{

          display.setCurrent(form);

          }

          }

          protected void pauseApp() {}

          protected void destroyApp(boolean unconditional) {}

          public static void quitApp() {

          instance.destroyApp(true);

          instance.notifyDestroyed();

          instance = null;

          }

          }

          class TestForm extends Form implements CommandListener {

          private Command exit = new Command("退出", Command.EXIT, 0);

          public TestForm() {

          super("J2ME平臺測試");

          String s;

          //CLDC版本屬性

          s = System.getProperty("microedition.configuration");

          append(getValue("CLDC版本", s));

          //MIPD版本屬性

          s = System.getProperty("microedition.profiles");

          append(getValue("MIDP版本",s));

          s = System.getProperty("microedition.platform");

          append(getValue("軟件平臺", s));

          s = System.getProperty("microedition.encoding");

          append(getValue("系統(tǒng)編碼", s));

          s = System.getProperty("microedition.locale");

          append(getValue("區(qū)域設(shè)置", s));

          s = System.getProperty("microedition.jtwi.version");

          append(getValue("JTWI", s));

          //判斷是否支持MMAPI

          s = System.getProperty("microedition.media.version");

          append(getValue("MMAPI", s));

          //判斷是否支持WMA

          s = System.getProperty("wireless.messaging.sms.smsc");

          if(s!=null) {

          append(getValue("WMA", "支持"));

          append(getValue("SMS", s));

          s = System.getProperty("wireless.messaging.mms.mmsc");

          append(getValue("MMS", s));

          } else

          append(getValue("WMA", null));

          //判斷是否支持藍牙

          s = System.getProperty("bluetooth.api.version");

          append(getValue("藍牙", s));

          //判斷是否支持個人信息管理

          s = System.getProperty("microedition.pim.version");

          append(getValue("PIM", s));

          //判斷是否支持文件系統(tǒng)

          s=System.getProperty("microedition.io.file.FileConnection. version");

          append(getValue("FileConnection", s));

          //判斷是否支持SIP

          s = System.getProperty("microedition.sip.version");

          append(getValue("SIP", s));

          //判斷是否支持M3G JSR 184

          s = System.getProperty("microedition.m3g.version");

          append(getValue("M3G", s));

          addCommand(exit);

          setCommandListener(this);

          }

          private String getValue(String prompt, String s) {

          return prompt + ":" + (s==null ? "不支持" : s) + "\n";

          }

          public void commandAction(Command c, Displayable d) {

          if(c==exit){

          DetectMIDlet.quitApp();

          }

          }

          }

          DetectMIDlet的運行界面如圖2-19所示。

          圖2-19 DetectMIDlet的運行界面


          這篇文章只是整理這方面的知識,并不是原創(chuàng)。所以大家湊合著看吧





          爬蟲工作室 -- 專業(yè)的手機軟件開發(fā)工作室
          3G視線 -- 專注手機軟件開發(fā)
          posted on 2007-08-28 21:59 3G工作室 閱讀(1574) 評論(1)  編輯  收藏

          Feedback

          # re: 手機J2ME環(huán)境測試程序--測試手機對jsr的支持以及其他信息 2007-08-29 21:43 張武科
          工作
            回復(fù)  更多評論
            


          只有注冊用戶登錄后才能發(fā)表評論。


          網(wǎng)站導(dǎo)航:
          博客園   IT新聞   Chat2DB   C++博客   博問  
           
          主站蜘蛛池模板: 新绛县| 佛冈县| 扶风县| 遂昌县| 彰武县| 广平县| 花莲市| 五河县| 湖北省| 甘孜| 新泰市| 屏山县| 桑日县| 保定市| 文成县| 东宁县| 阿荣旗| 瓦房店市| 岳西县| 乌兰浩特市| 金乡县| 汝州市| 宿迁市| 卢龙县| 眉山市| 莱阳市| 和静县| 绥宁县| 宽城| 金沙县| 辽宁省| 奉节县| 保定市| 石首市| 延安市| 宽甸| 门头沟区| 泉州市| 巢湖市| 新乡县| 邹平县|