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

          3G 手機開發網

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

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

          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應用程序的屬性

          MIDlet可以訪問兩種運行時的屬性值:系統屬性和應用程序屬性。

          1.系統屬性

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

          表2-3列舉了系統屬性。

          表2-3 MIDP應用程序系統屬性

          JSR

          屬性名稱

          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

          依賴于底層實現


          microedition.pim.version

          1.0

          118

          microedition.locale

          null


          microedition.profiles

          MIDP-2.0


          microedition.commports

          依賴于底層實現


          microedition.hostname

          依賴于底層實現

          120

          wireless.messaging.sms.smsc

          依賴于底層實現

          139

          microedition.platform

          依賴于底層實現


          microedition.encoding

          ISO8859-1


          microedition.configuration

          CLDC-1.1


          microedition.profiles

          依賴于底層實現

          177

          microedition.smartcardslots

          依賴于底層實現

          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

          依賴于底層實現


          microedition.profiles

          IMP-1.0

          205

          wireless.messaging.sms.smsc

          依賴于底層實現

          205

          wireless.messaging.mms.mmsc

          依賴于底層實現

          2.應用程序屬性

          應用程序屬性值是在應用程序描述符文件或者MANIFEST文件中定義的,當我們部署應用程序的時候可以定義應用程序屬性。比如下面是一個典型的JAD文件內容。

          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就是應用程序屬性值,我們可以通過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");

          }

          //這里省略了其他代碼

          }

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

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

          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) {

          //首次啟動應用程序

          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("系統編碼", s));

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

          append(getValue("區域設置", 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));

          //判斷是否支持文件系統

          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的運行界面


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





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

          Feedback

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


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


          網站導航:
           
          主站蜘蛛池模板: 商南县| 乐都县| 都昌县| 抚州市| 论坛| 潮州市| 尼勒克县| 莫力| 延吉市| 宜宾县| 沙坪坝区| 韶山市| 吴堡县| 平果县| 安徽省| 景东| 张掖市| 阳朔县| 扬州市| 和硕县| 周宁县| 乌拉特中旗| 兴安盟| 晋州市| 仙游县| 鹤庆县| 精河县| 高清| 北辰区| 昔阳县| 武川县| 衡山县| 临澧县| 合山市| 射洪县| 扶绥县| 德州市| 孟津县| 延吉市| 明星| 尼木县|