1. System.getProperty(String key)標準的5個屬性鍵 列表如下:
microedition.configuration
microedition.configuration
代表手機支持的CLDC版本,返回格式值爲“CLDC-1.0”或“CLDC-2.0”
microedition.profiles
代表手機支持的MIDP版本,返回格式值爲“MIDP-1.0”或“MIDP-2.0”
microedition.encoding
microedition.encoding
代表手機默認的字符集名稱,返回值格式爲“ISO-8859-1”
microedition.locale
microedition.locale
代表手機所在的國家或地區,返回值格式爲“en-US”
microedition.platform
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等等。
如果想獲得其他的信息,請參考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
MIDlet-Name
MIDlet-Jar-Size
MIDlet-Jar-URL
MIDlet-Vendor
各個廠商的手機或許會有自己的擴充鍵值。
3. 常見擴充
microedition.commports
代表手機可以使用的串口列表,返回值中各個串口之間使用逗號分隔
microedition.hostname
microedition.hostname
MIDP2.0定義,代表本地主機名稱,需要手機支持。
microedition.jtwi.version
microedition.jtwi.version
代表手機支持的JTWI版本,值必須是“1.0”
(1)可選包屬性
microedition.media.version
microedition.media.version
代表手機支持的MMAPI版本,如果不支持則返回null
microedition.pim.version
microedition.pim.version
代表手機支持的PIM API版本,如果不支持則返回null
microedition.m3g.version
microedition.m3g.version
代表手機支持的M3G API版本,如果不支持則返回null
microedition.location.version
microedition.location.version
代表手機支持的Location API版本,如果不支持則返回null
bluetooth.api.version
bluetooth.api.version
代表手機支持的BT API版本,如果不支持則返回null
microedition.io.file.FileConnection.version
microedition.io.file.FileConnection.version
代表手機支持的FC API版本,如果不支持則返回null
microedition.global.version
代表手機支持的Mobile Internationalization API(JSR-238)版本,如果不支持則返回null
microedition.chapi.version
microedition.chapi.version
代表手機支持的CH(Content Handler) API(JSR211)版本,如果不支持則返回null
microedition.sip.version
microedition.sip.version
代表手機支持的SIP API版本,如果不支持則返回null
(2)MMAPI屬性
supports.mixing
supports.mixing
代表手機是否支持混音(同時播放多個Player),返回值爲“true”或“false”
supports.audio.capture
supports.audio.capture
代表手機是否支持聲音捕獲(錄音),返回值爲“true”或“false”
supports.video.capture
supports.video.capture
代表手機是否支持視頻捕獲(錄像),返回值爲“true”或“false”
supports.recording
supports.recording
代表手機是否支持記錄(record),返回值爲“true”或“false”
audio.encodings
代表手機支持的聲音格式,返回值格式爲“encoding=audio/wav”,多個格式之間使用至少一個空格進行間隔
video.encodings
代表手機支持的視頻格式,返回值格式爲“encoding=video/3gpp”,多個格式之間使用至少一個空格進行間隔
video.snapshot.encodings
代表手機使用getSnapshot方法獲得的視頻快照格式,返回值格式爲 “encoding=png”,多個格式之間使用至少一個空格進行間隔
streamable.contents
streamable.contents
代表手機支持的流媒體格式,返回null代表不支持
(3)Wireless Messaging API屬性
wireless.messaging.sms.smsc
(3)Wireless Messaging API屬性
wireless.messaging.sms.smsc
代表手機發送短信時的短信服務中心號碼
(4)FileConnection API 屬性
fileconn.dir.photos
(4)FileConnection API 屬性
fileconn.dir.photos
代表手機中存儲照片和其它圖片的目錄,例如“file:///c:/My files/ Images /”
fileconn.dir.videos
fileconn.dir.videos
代表手機中存儲視頻的目錄,例如“file:///c:/My files/Video clips/”
fileconn.dir.tones
fileconn.dir.tones
代表手機中存儲聲音的目錄,例如“file:///c:/My files/Tones/”
fileconn.dir.memorycard
fileconn.dir.memorycard
代表手機中存儲卡的根目錄。例如“file:///d:/”
fileconn.dir.photos.name
fileconn.dir.photos.name
代表手機中圖片目錄的名稱,例如“Images”
fileconn.dir.videos.name
fileconn.dir.videos.name
代表手機中視頻目錄的名稱,例如“Video clips”
fileconn.dir.tones.name
fileconn.dir.tones.name
代表手機中聲音目錄的名稱,例如“Sound clips”
file.separator
file.separator
代表手機中的文件分隔符,例如“/”
fileconn.dir.memorycard.name
fileconn.dir.memorycard.name
代表手機中存儲卡的名稱,例如“Memory card”