×
Namespaces

Variants
Actions
Revision as of 05:26, 23 October 2013 by hamishwillee (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

如何实现打电话功能

From Nokia Developer Wiki
Jump to: navigation, search
WP Metro Icon Chinese.png
Article Metadata

文章
max.chen 在 24 Jul 2011 创建
最后由 hamishwillee 在 23 Oct 2013 编辑

介绍

platformRequest()是MIDlet类的一个方法,通过这个方法可以访问设备的一些功能。它的定义如下:

public final boolean platformRequest(String URL) 
throws ConnectionNotFoundException

如果URL的指定为tel:<number>(详细信息请参考RFC2806) 时,系统会将其转换成一个语音电话并且启动系统的电话程序去处理这个请求。参数中的电话号码会由系统的电话程序转化成DTMF信号。


源代码

import javax.microedition.io.ConnectionNotFoundException;
import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.CommandListener;
import javax.microedition.lcdui.Display;import javax.microedition.lcdui.Displayable;
import javax.microedition.lcdui.Form;import javax.microedition.midlet.MIDlet;
 
public class ExampleMIDlet extends MIDlet implements CommandListener {
private Command callCommand;
private Command exitCommand;
private Form mainForm;
 
// The phone number to call
private final String PHONE_NUMBER = "123456789";
 
/**
* Constructor. Constructs the object and initializes displayables.
*/

public ExampleMIDlet() {
mainForm = new Form("ExampleMIDlet");
callCommand = new Command("Call", Command.SCREEN, 0);
mainForm.addCommand(callCommand);
exitCommand = new Command("Exit", Command.EXIT, 0);
mainForm.addCommand(exitCommand);
mainForm.setCommandListener(this);
}
/**
* Calls the specified number.
*/

private void call(String number) {
try {
platformRequest("tel:" + number);
} catch (ConnectionNotFoundException ex) {
// TODO: Exception handling
}
}
 
/**
* Called when the MIDlet is started.
*/

public void startApp() {
Display.getDisplay(this).setCurrent(mainForm);
}
 
// Other inherited methods omitted for brevity
// ...
/**
* From CommandListener.
* Called by the system to indicate that a command has been invoked on a
* particular displayable.
* @param command the command that was invoked
* @param displayable the displayable where the command was invoked
*/

public void commandAction(Command command, Displayable displayable) {
if (command == callCommand) {
call(PHONE_NUMBER);
} else if (command == exitCommand) {
// Exit the MIDlet
destroyApp(true);
notifyDestroyed();
}
}
}


相关链接

This page was last modified on 23 October 2013, at 05:26.
111 page views in the last 30 days.

Was this page helpful?

Your feedback about this content is important. Let us know what you think.

 

Thank you!

We appreciate your feedback.

×