介绍MIDP应用程序的属性

MIDlet是在MIDP中提出的一种应用程序模型,目前在J2ME中应用最为广泛。本文将主要介绍MIDP应用程序的属性问题。读者可以参考 MIDP Application Properties

    MIDlet可以访问两种运行时的属性值:系统和应用程序的。

    系统属性的概念是在CLDC(Connected Limited Device Configuration)中定义的,属性值被写入底层的系统,我们可以读取它们但是不能修改这些属性值。如果你想读取一个系统属性值那么你可以使用System类的静态方法System.getProperty()来读取。经常有网友会询问如何读取手机号码或者IMEI号码,其实这些你应该参考具体机型的开发文档。各个厂商的实现都是不一样的。为了让大家查找方便这里列出在J2ME中定义的系统属性值,如果你的手机支持相关的JSR,那么就可以通过上述方法取得属性值。

JSRProperty Name
Default Value¹
30microedition.platformnull
 microedition.encodingISO8859_1
 microedition.configurationCLDC-1.0
 microedition.profilesnull
37microedition.localenull
 microedition.profilesMIDP-1.0
75microedition.io.file.FileConnection.version1.0
 file.separator(impl-dep)
 microedition.pim.version1.0
118microedition.localenull
 microedition.profilesMIDP-2.0
 microedition.commports(impl-dep)
 microedition.hostname(impl-dep)
120wireless.messaging.sms.smsc(impl-dep)
139microedition.platform(impl-dep)
 microedition.encodingISO8859-1
 microedition.configurationCLDC-1.1
 microedition.profiles(impl-dep)
177microedition.smartcardslots(impl-dep)
179microedition.location.version1.0
180microedition.sip.version1.0
184microedition.m3g.version1.0
185microedition.jtwi.version1.0
195microedition.locale(impl-dep)
 microedition.profilesIMP-1.0
205wireless.messaging.sms.smsc(impl-dep)
205wireless.messaging.mms.mmsc(impl-dep)

      应用程序属性值是在应用程序描述符文件或者MANIFEST文件中定义的(其中MANIFEST文件是打包在jar文件中的),当我们部署应用程序的时候会定义应用程序属性。比如下面是一个典型的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;

		public MyMIDlet(){
			suiteName = getAppProperty( "MIDlet-Name" );
			... // more stuff
		}

		... // etc.
	}


     属性值是大小写敏感的,如果属性值在系统,jad文件和manifest文件中都没有定义的话,那么将返回null。如果在jad文件和manifest文件中定义了同样的属性值,那么会出现如下两种情况:如果应用程序是MIDP2.0种的信任应用程序,那么AMS将会拒绝安装。否则在jad文件中的属性值会覆盖manifest中的值。

    在jad文件中使用属性值有一定的好处,如果你需要更改一些数据而又不想重新编译代码、打包的话,那么你可以在jad中定义一些属性值。这样可以配置你的应用程序,想想是不是和你在j2se应用中使用属性文件类似。但是不要在jad文将中定义大量的数据,因为很多设备都是对jad文件的大小有限制的。

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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值