System.getProperty(String key)和MIDlet.getAppProperty(String key)

1. System.getProperty(String key)标准的5个属性键 列表如下:
microedition.configuration   
代表手机支持的CLDC版本,返回格式值为“CLDC-1.0”或“CLDC-2.0”
microedition.profiles           
代表手机支持的MIDP版本,返回格式值为“MIDP-1.0”或“MIDP-2.0”
microedition.encoding         
代表手机默认的字符集名称,返回值格式为“ISO-8859-1”
microedition.locale              
代表手机所在的国家或地区,返回值格式为“en-US”
microedition.platform          
代表手机的品牌和型号,Nokia手机的返回值格式为“Nokia6310i/4.42”
 
System类中currentTimeMillis() 可以获得手机的当前时间。
如果想获得其他的信息,请参考System.getProperty()方法
具体的使用方法如下:
package fancy.test;

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

public class Prop extends MIDlet implements CommandListener
{
private Display display;
private form props;


private Command exitCommand = new Command("Exit", Command.EXIT, 1);

public Prop()
{
display = Display.getDisplay(this);
}

public void startApp()
{
props = new form("System Properties");
props.append("Hello World!\n");
long time=System.currentTimeMillis();
props.append("current time:"+time+"\n");

props.append("microedition.configuration:"+
System.getProperty("microedition.configuration")+"\n");

props.append("microedition.profiles:"+
System.getProperty("microedition.profiles")+"\n");

props.append("microedition.platform:"+
System.getProperty("microedition.platform")+"\n");

props.append("microedition.locale:"+
System.getProperty("microedition.locale")+"\n");

props.append("microedition.encoding:"+
System.getProperty("microedition.encoding")+"\n");

props.append("java.version:"+System.getProperty("java.version")+"\n");//null

props.append("java.vendor:"+System.getProperty("java.vendor")+"\n");//null

props.append("java.vm.name:"+System.getProperty("java.vm.name")+"\n");//null

props.append("java.vm.version:"+System.getProperty("java.vm.version")+"\n");//null

props.append("os.name:"+System.getProperty("os.name")+"\n");//null

props.append("os.arch:"+System.getProperty("os.arch")+"\n");//null

props.append("os.version:"+System.getProperty("os.version")+"\n");//null

props.append("user.name:"+System.getProperty("user.name")+"\n");//null

props.addCommand(exitCommand);

props.setCommandListener(this);

display.setCurrent(props);
}

public void commandAction(Command c, Displayable s)
{
if (c == exitCommand)
{
destroyApp(false);
notifyDestroyed();
}
}

public void destroyApp(boolean unconditional)
{
}

public void pauseApp()
{
display.setCurrent(null);
props = null;
}
}
这个程序的作用是输出系统中各个环境属性的值。诀窍是使用System类的getProperty()方
法。请注意,J2ME核心包的System类已绮不支持getProperties()方法了,而且很多环境属性都
不再支持了,比如java.version、java.vendor等等。


2. MIDlet.getAppProperty(String key)标准的属性键 列表如下:
MIDlet-Name
MIDlet-Jar-Size
MIDlet-Jar-URL
MIDlet-Vendor
各个厂商的手机或许会有自己的扩充键值。

3. 常见扩充
microedition.commports
代表手机可以使用的串口列表,返回值中各个串口之间使用逗号分隔
microedition.hostname
MIDP2.0定义,代表本地主机名称,需要手机支持。
microedition.jtwi.version
代表手机支持的JTWI版本,值必须是“1.0”

(1)可选包属性
microedition.media.version
代表手机支持的MMAPI版本,如果不支持则返回null
microedition.pim.version
代表手机支持的PIM API版本,如果不支持则返回null
microedition.m3g.version     
代表手机支持的M3G API版本,如果不支持则返回null
microedition.location.version   
代表手机支持的Location API版本,如果不支持则返回null
bluetooth.api.version           
代表手机支持的BT API版本,如果不支持则返回null
microedition.io.file.FileConnection.version   
代表手机支持的FC API版本,如果不支持则返回null
microedition.global.version   
代表手机支持的Mobile Internationalization API(JSR-238)版本,如果不支持则返回null
microedition.chapi.version    
代表手机支持的CH(Content Handler) API(JSR211)版本,如果不支持则返回null
microedition.sip.version       
代表手机支持的SIP API版本,如果不支持则返回null

(2)MMAPI属性
supports.mixing
代表手机是否支持混音(同时播放多个Player),返回值为“true”或“false”
supports.audio.capture       
代表手机是否支持声音捕获(录音),返回值为“true”或“false”
supports.video.capture       
代表手机是否支持视频捕获(录像),返回值为“true”或“false”
supports.recording             
代表手机是否支持记录(record),返回值为“true”或“false”
audio.encodings
代表手机支持的声音格式,返回值格式为“encoding=audio/wav”,多个格式之间使用至少一个空格进行间隔
video.encodings
代表手机支持的视频格式,返回值格式为“encoding=video/3gpp”,多个格式之间使用至少一个空格进行间隔
video.snapshot.encodings   
代表手机使用getSnapshot方法获得的视频快照格式,返回值格式为 “encoding=png”,多个格式之间使用至少一个空格进行间隔
streamable.contents
代表手机支持的流媒体格式,返回null代表不支持

(3)Wireless Messaging API属性
wireless.messaging.sms.smsc  
代表手机发送短信时的短信服务中心号码

(4)FileConnection API
属性

fileconn.dir.photos
代表手机中存储照片和其它图片的目录,例如“file:///c:/My files/ Images /”
fileconn.dir.videos
代表手机中存储视频的目录,例如“file:///c:/My files/Video clips/”
fileconn.dir.tones
代表手机中存储声音的目录,例如“file:///c:/My files/Tones/”
fileconn.dir.memorycard
代表手机中存储卡的根目录。例如“file:///d:/”
fileconn.dir.photos.name
代表手机中图片目录的名称,例如“Images”
fileconn.dir.videos.name
代表手机中视频目录的名称,例如“Video clips”
fileconn.dir.tones.name
代表手机中声音目录的名称,例如“Sound clips”
file.separator
代表手机中的文件分隔符,例如“/”
fileconn.dir.memorycard.name
代表手机中存储卡的名称,例如“Memory card”
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章