程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> JAVA編程 >> J2ME >> 開發高可移植性J2ME的軟件(3)

開發高可移植性J2ME的軟件(3)

編輯:J2ME

簡單的Demo

下面是簡單的測試環境的代碼,有經驗的朋友可以很容易就就跑起來。

代碼片段

/**
* getSysInfo
*/
private void getSysInfo() {
addInfo( "Microedition Configuration: ",
getInfo(System.getProperty( "microedition.configuration")));
addInfo( "Microedition Profiles: ",
getInfo(System.getProperty( "microedition.profiles")));
addInfo( "microedition.jtwi.version:",
getInfo(System.getProperty( "microedition.jtwi.version")));
addInfo( "microedition.platform:",
getInfo(System.getProperty( "microedition.platform")));
addInfo( "microedition.locale:",
getInfo(System.getProperty( "microedition.locale")));
addInfo( "default encoding:",
getInfo(System.getProperty( "microedition.encoding")));
addInfo( "microedition.commports",
getInfo(System.getProperty( "microedition.commports")));
addInfo( "microedition.hostname",
getInfo(System.getProperty( "microedition.hostname")));
// microedition.smartcardslots
addInfo( " microedition.smartcardslots",
getInfo(System.getProperty( " microedition.smartcardslots")));
addInfo( "com.nokia.Network.Access",
getInfo(System.getProperty( "com.nokia.Network.Access")));
addInfo( "com.nokia.mid.dateformat",
getInfo(System.getProperty( "com.nokia.mid.dateformat")));
addInfo( "com.nokia.mid.timeformat",
getInfo(System.getProperty( "com.nokia.mid.timeformat")));
addInfo( "com.nokia.memoryramfree",
getInfo(System.getProperty( "com.nokia.memoryramfree")));
addInfo( "com.nokia.mid.batterylevel",
getInfo(System.getProperty( "com.nokia.mid.batterylevel")));
addInfo( "com.nokia.mid.countrycode",
getInfo(System.getProperty( "com.nokia.mid.countrycode")));
addInfo( "com.nokia.mid.Networkstatus",
getInfo(System.getProperty( "com.nokia.mid.Networkstatus")));
addInfo( "com.nokia.mid.Networksignal",
getInfo(System.getProperty( "com.nokia.mid.Networksignal")));
addInfo( "com.nokia.mid.Networkid",
getInfo(System.getProperty( "com.nokia.mid.Networkid")));
addInfo( "com.nokia.mid.Networkavailability",
getInfo(System.getProperty( "com.nokia.mid.Networkavailability")));
addInfo( "com.nokia.mid.cellid",
getInfo(System.getProperty( "com.nokia.mid.cellid")));
addInfo( "com.nokia.mid.imei",
getInfo(System.getProperty( "com.nokia.mid.imei")));
addInfo( "com.nokia.mid.imsi",
getInfo(System.getProperty( "com.nokia.mid.imsi")));
String[] timeZoneIDs = Java.util.TimeZone.getAvailableIDs();
StringBuffer timeZonesBuffer = new StringBuffer();
for (int i = 0; i < timeZoneIDs.length; i++) {
timeZonesBuffer.append(timeZoneIDs[i]).append('\n');
}
addInfo( "Total memory:",
Long.toString(Runtime.getRuntime().totalMemory()) + " bytes");
addInfo( "Free memory:",
Long.toString(Runtime.getRuntime().freeMemory()) + " bytes");
addInfo( "Available TimeZones:", timeZonesBuffer.toString());
addInfo( "Default TimeZone:", Java.util.TimeZone.getDefault().getID());
addInfo( "com.siemens.mp.lcdui.Image", hasClassExit("com.sIEmens.mp.lcdui.Image") + "");
addInfo( "com.motorola.phonebook.PhoneBookRecord", hasClassExit("com.motorola.phonebook.PhoneBookRecord") + "");
addInfo( "com.motorola.Dialer", hasClassExit("com.motorola.Dialer") + "");
addInfo( "com.jblend.util.Case", hasClassExit("com.jblend.util.Case") + "");
addInfo( "com.samsung.util.AudioClip", hasClassExit("com.samsung.util.AudioClip") + "");
addInfo( "com.mot.iden.multimedia.Lighting", hasClassExit("com.mot.iden.multimedia.Lighting") + "");
}
private boolean hasClassExit(String aClassName) {
try {
Class.forName(aClassName);
return true;
} catch (Exception e) {
return false;
}
}
public String getInfo(String info) {
if (info == null) {
return "<unknown>";
} else {
return info;
}
}
public void addInfo(String name, String value) {
iForm.append(new StringItem(name, value));
}

代碼片段2

public void collectInfos(TestClIEnt midlet, Display display) {
try {
Class.forName( "Javax.microedition.media.control.VideoControl");
addInfo( "MMAPI: ", "yes" );
addInfo( "MMAPI-Version: ", getInfo(System.getProperty("microedition.media.version")) );
} catch (ClassNotFoundException e) {
addInfo( "MMAPI: ", "no" );
}
try {
Class.forName( "Javax.wireless.messaging.Message");
addInfo( "WMAPI 1.1: ", "yes" );
try {
Class.forName( "Javax.wireless.messaging.MultipartMessage");
addInfo( "WMAPI 2.0: ", "yes" );
} catch (ClassNotFoundException e) {
addInfo( "WMAPI 2.0: ", "no" );
}
} catch (ClassNotFoundException e) {
addInfo( "WMAPI 1.1: ", "no" );
}
try {
Class.forName( "Javax.bluetooth.DiscoveryAgent");
addInfo( "Bluetooth-API: ", "yes" );
try {
Class.forName( "Javax.obex.ClIEntSession");
addInfo( "Bluetooth-Obex-API: ", "yes" );
} catch (ClassNotFoundException e) {
addInfo( "Bluetooth-Obex-API: ", "no" );
}
} catch (ClassNotFoundException e) {
addInfo( "Bluetooth-API: ", "no" );
}
try {
Class.forName( "Javax.microedition.m3g.Graphics3D");
addInfo( "M3G-API: ", "yes" );
} catch (ClassNotFoundException e) {
addInfo( "M3G-API: ", "no" );
}
try {
Class.forName( "Javax.microedition.pim.PIM");
addInfo( "PIM-API: ", "yes" );
} catch (ClassNotFoundException e) {
addInfo( "PIM-API: ", "no" );
}
try {
Class.forName( "Javax.microedition.io.file.FileSystemRegistry");
addInfo( "FileConnection-API: ", "yes" );
} catch (ClassNotFoundException e) {
addInfo( "FileConnection-API: ", "no" );
}
try {
Class.forName( "Javax.microedition.location.Location");
addInfo( "Location-API: ", "yes" );
} catch (Java.lang.Throwable e) {
addInfo( "Location-API: ", "no" );
}
try {
Class.forName( "Javax.microedition.XML.rpc.Operation");
addInfo( "WebServices-API: ", "yes" );
} catch (ClassNotFoundException e) {
addInfo( "WebServices-API: ", "no" );
}
try {
Class.forName( "Javax.microedition.sip.SipConnection");
addInfo( "SIP-API: ", "yes" );
} catch (ClassNotFoundException e) {
addInfo( "SIP-API: ", "no" );
}
try {
Class.forName( "com.nokia.mid.ui.FullCanvas");
addInfo( "Nokia-UI-API: ", "yes" );
} catch (ClassNotFoundException e) {
addInfo( "Nokia-UI-API: ", "no" );
}
try {
Class.forName( "com.sIEmens.mp.MIDlet");
addInfo( "SIEmens-Extension-API: ", "yes" );
try {
Class.forName( "com.sIEmens.mp.color_game.GameCanvas");
addInfo( "SIEmens-ColorGame-API: ", "yes" );
} catch (ClassNotFoundException e) {
addInfo( "SIEmens-ColorGame-API: ", "no" );
}
} catch (ClassNotFoundException e) {
addInfo( "SIEmens-Extension-API: ", "no" );
}
}

附表:屬性表

表1 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代表不支持

表2 Wireless Messaging API屬性

屬性名稱

屬性作用

wireless.messaging.sms.smsc

代表手機發送短信時的短信服務中心號碼

表3FileConnection 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.private
(Nokia S40不支持)

代表手機中MIDlet的私有工作目錄,例如“file:///c:/System/MIDlets/[1015f294]/scratch”

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”

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved