javax.microedition.midlet.MIDlet类提供了platformRequest()方法来请求设备来完成特定的请求,请求的内容由platformRequest()方法的String类型的参数url来标识。可能是调用浏览器打开某个特定的wap页面,也可以是呼叫电话。)
import javax.microedition.io.ConnectionNotFoundException;
import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
/**
*
* @author Administrator
* @version
*/
public class TeleMIDlet extends MIDlet implements CommandListener {
private Display display = null;
private List main = null;
public void startApp() {
if(display == null){
display = Display.getDisplay(this);
main = new List("测试电话功能", List.IMPLICIT);
main.append("13810000000", null);//这里的电话号码是虚拟的
main.append("13810000001", null);//这里的电话号码是虚拟的
main.setCommandListener(this);
}
display.setCurrent(main);
}
public void pauseApp() {}
public void destroyApp(boolean unconditional) {}
public void commandAction(Command cmd,Displayable displayable){
if(cmd == List.SELECT_COMMAND){
String number = main.getString(main.getSelectedIndex());
try{
this.platformRequest("tel:"+number);
}catch(ConnectionNotFoundException ex){
ex.printStackTrace();
}
}
}
}
下面是WAP中实现手机拨号功能代码(是用WMLSCRIPT哦!):
<input name="phone_no" format="*m" value="13"/>
<do type="option" label="呼出号">
<go href="wtai://wp/mc;$(phone_no)"/>
</do><br/>
或者直接写入电话号码的方式:
<a href="wtai://wp/mc;1331597312*">拨打电话</a>
(说明一下:WML中可以调用设备的WTAI函数来呼叫特定的电话号码)