Invoking Platform Services in MIDP 2.0

Article

Invoking Platform Services in MIDP 2.0

 
 
By C. Enrique Ortiz, May 2004  

Version 2.0 of the Mobile Information Device Profile (MIDP) includes a facility that enables MIDlets to invoke external platform services; to start downloading and installing a MIDlet suite for example, or to initiate a voice call. Access is through the method javax.microedition.midlet.MIDlet.platformRequest().

Using the Request Method

The platformRequest() method takes one input argument, a String URL that it passes to the platform's application management software (AMS). The AMS examines the scheme of the URL, and if appropriate logic is available loads or invokes the appropriate service. An empty non-null URL string cancels any pending platform requests. The platformRequest() method returns true if the MIDlet suite must exit before the external platform service can be invoked, and it throws a ConnectionNotFoundException if the platform cannot handle the URL argument.

The MIDP 2.0 specification defines two URL schemes and corresponding platform services:

  • If the URL points to a MIDlet suite's JAD or JAR file, for example http://www.j2medeveloper.com/ota/basicpush.jad, the platform request is for download and installation of the MIDlet suite, using the platform's normal installation process.
  • If the URL scheme is tel:, for example tel:+358-555-1234567, the URL must be passed to the device's application responsible for initiating voice calls.

Device manufactures are free to implement additional platform services. For example, one likely platform service would be to invoke a web browser when the MIDlet supplies an http: URL such as http://developers.sun.com/mobility.

It's important to understand that platformRequest() is a non-blocking method, and that the specification doesn't require platforms to queue multiple calls. On some platforms, only the most recent call to platformRequest() will be honored.

MIDlet Life-Cycle Considerations

You must take the MIDlet life-cycle into account when you use platformRequest().

Some MIDP platforms are more restricted than others. For example, some don't support concurrent processing, so the MIDlet must exit before the platform can honor a service request. Recall that platformRequest() returns true in such cases, giving your MIDlet fair warning that it must exit.

If the platform request is to download and install an update of the currently loaded MIDlet suite, the currently running MIDlet is first terminated.

In both these cases, the MIDlet must be prepared to exit gracefully, first managing its state so as to resume appropriately later.

J2ME Wireless Toolkit Support

The J2ME Wireless Toolkit supports the platformRequest() method, but before using the method you must tell the toolkit what to do when it's invoked. You can associate only one platform service with platformRequest(). For instance, if for testing purposes you associate the method with your browser, the browser will be launched every time you call platformRequest(). If you need more flexibility, you can associate platformRequest() with a script that will use the URL scheme to route the request to the right handler.

To associate a particular platform service with platformRequest(), simply add a com.sun.midp.midlet.platformRequestCommand attribute to the system.config file in the toolkit's lib directory. For example, to invoke the Mozilla browser whenever platformRequest() is called, add the following to system.config:

# Associate the Mozilla browser with platformRequest() - Windows
com.sun.midp.midlet.platformRequestCommand:
"C:/Program Files/mozilla.org/Mozilla/mozilla.exe" 

Given this setting, the call platformRequest("http://developers.sun.com/mobility") will launch Mozilla, and the browser will navigate to Sun's developer mobility portal.

For more information, see the javadoc for the javax.microedition.midlet.MIDlet class.

Acknowledgements

Thanks to Gary Adams for reviewing this technical tip.

 原文地址:

http://developers.sun.com/mobility/midp/ttips/platformRequest/

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值