十一月's profileNOVEMBREBlogListsGuestbookMore Tools Help

Blog


    January 30

    在J2ME和WAP中实现电话呼叫功能

    本文介绍如何在J2ME平台和WAP页面实现电话呼叫的功能。关于WAP和J2ME的区别并不在讨论范畴,读者可以自行查阅资料。

           MIDP 1.0中没有提供电话呼叫的功能。在MIDP 2.0中,javax.microedition.midlet.MIDlet类提供了platformRequest()方法来请求设备来完成特定的请求,请求的内容由platformRequest()方法的String类型的参数url来标识。可能是调用浏览器打开某个特定的wap页面,也可以是呼叫电话。在设备资源可用的时候,系统会把MIDlet放在后台执行,而把特定的应用程序,例如电话程序或者浏览器放在前台来执行。呼叫电话的时候可以使用如下的形式:
    JAVA手机网[www.cnjm.net]

               try{
                   this.platformRequest("tel:13810000000");
               }catch(ConnectionNotFoundException ex){
                   ex.printStackTrace();
               }

    JAVA手机网[www.cnjm.net]
    这里提供了一个简单的例子,在Nokia 7610(支持MIDP 2.0)上测试通过,成功呼叫了指定的电话。

    /*
    * TeleMIDlet.java
    *
    * Created on 2005年12月15日, 下午9:56
    */

    package com.j2medev.call;

    import javax.microedition.io.ConnectionNotFoundException;
    import javax.microedition.midlet.*;
    import javax.microedition.lcdui.*;
    JAVA手机网[www.cnjm.net]

    /**
    *
    * @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);//这里的电话号码是虚拟的
    JAVA手机网[www.cnjm.net]
               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){
    JAVA手机网[www.cnjm.net]
               String number = main.getString(main.getSelectedIndex());
               try{
                   this.platformRequest("tel:"+number);
               }catch(ConnectionNotFoundException ex){
    JAVA手机网[www.cnjm.net]
                   ex.printStackTrace();
               }
           }
       }
    }

           相比J2ME技术,WAP更类似于Web,是一种服务器端为主的技术。在WML中可以调用设备的WTAI函数来呼叫特定的电话号码,代码如下所示:

    JAVA手机网[www.cnjm.net]
    <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>


    在MIDP 2.0和WAP平台中都对电话呼叫提供了支持,本文进行了简单的总结,希望对您的实际项目有所帮助。
    来自:http://www.cnjm.net/tech/article1106.html

    Comments

    Please wait...
    Sorry, the comment you entered is too long. Please shorten it.
    You didn't enter anything. Please try again.
    Sorry, we can't add your comment right now. Please try again later.
    To add a comment, you need permission from your parent. Ask for permission
    Your parent has turned off comments.
    Sorry, we can't delete your comment right now. Please try again later.
    You've exceeded the maximum number of comments that can be left in one day. Please try again in 24 hours.
    Your account has had the ability to leave comments disabled because our systems indicate that you may be spamming other users. If you believe that your account has been disabled in error please contact Windows Live support.
    Complete the security check below to finish leaving your comment.
    The characters you type in the security check must match the characters in the picture or audio.

    To add a comment, sign in with your Windows Live ID (if you use Hotmail, Messenger, or Xbox LIVE, you have a Windows Live ID). Sign in


    Don't have a Windows Live ID? Sign up

    Trackbacks

    The trackback URL for this entry is:
    http://novembre-winter.spaces.live.com/blog/cns!B4EC2BD80D2AD637!136.trak
    Weblogs that reference this entry
    • None