手机J2ME环境测试程序--测试手机对jsr的支持以及其他信息

相信做手机开发的都知道,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的运行界面

这篇文章只是整理这方面的知识,并不是原创。所以大家凑合着看吧

  
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值