通过平台请求拨打电话号码



我尝试了两天来编写拨打电话号码的代码,但我失败了

我已经写了一个midlet和一个名为main的表单作为可显示的表单包含一个文本字段和

命令。

当应用程序启动时,应出现表单并呼叫写入的拨打号码

文本字段 当命令按下时。

拨号过程对我不起作用.

import javax.microedition.io.ConnectionNotFoundException;
import javax.microedition.lcdui.Command; 
import javax.microedition.lcdui.CommandListener;
import javax.microedition.lcdui.Display;
import javax.microedition.lcdui.*;
import javax.microedition.lcdui.Displayable.*;
import javax.microedition.lcdui.Form.*;
 import javax.microedition.midlet.MIDlet;
 import java.io.IOException;
 import java.io.InputStreamReader;
 import javax.microedition.lcdui.*;
 import javax.microedition.midlet.MIDlet;
public class DiallNumber extends MIDlet implements CommandListener
 {
    String num;
 private  Form main;
 private Command call,dial;
 private TextField phoneField;
 Display display;
 public DiallNumber()
    {

 main = new Form("main");
phoneField = new TextField("label","",10,phoneField.PHONENUMBER);
call = new Command("call",call.OK,0);
    main.append(phoneField);
    main.addCommand(call);
    num=this.phoneField.getString().trim();
main.setCommandListener(this);
 }
/**}
 * From MIDlet. Called when the MIDlet is started.
 */
 public void startApp()
 {
 // The initial display is the first form
display = Display.getDisplay(this);
   display.setCurrent(main);


     }
public void call( String number) {
 try {
 platformRequest("tel:"+number);
 } catch (ConnectionNotFoundException ex) {
 // TODO: Exception handling
 }
 }
 public void commandAction(Command c, Displayable d){
     if(d==main)
     {
         if(c==call)
              call(""+num);
     }
 }

 public void pauseApp()
 {
 // No implementation required
 }

/*

 * /
 */

/**
 * From MIDlet. Called to signal the MIDlet to terminate.
 *
* @param unconditional
 * whether the MIDlet has to be unconditionally terminated
 */
 public void destroyApp(boolean unconditional)
 {
 // No implementation required
 }
/**
 * 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
 */

       }

我的日志跟踪

Copying 1 file to C:UsersELHADIDocumentsNetBeansProjectsDiallNumber2distnbrun5217990045006831680
Copying 1 file to C:UsersELHADIDocumentsNetBeansProjectsDiallNumber2distnbrun5217990045006831680
Jad URL for OTA execution: http://localhost:8082/servlet/org.netbeans.modules.mobility.project.jam.JAMServlet/C%3A/Users/ELHADI/Documents/NetBeansProjects/DiallNumber2/dist//DiallNumber2.jad
Starting emulator in execution mode
Installing suite from: http://127.0.0.1:49320/DiallNumber2.jad
[WARN] [rms     ] javacall_file_open: _wopen failed for: C:UsersELHADIjavame-sdk3.0workappdb_delete_notify.dat

我已经解决了问题

import javax.microedition.io.ConnectionNotFoundException;
import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.CommandListener;
import javax.microedition.lcdui.Display;
import javax.microedition.lcdui.*;
import javax.microedition.lcdui.Displayable.*;
import javax.microedition.lcdui.Form.*;
 import javax.microedition.midlet.MIDlet;
 import java.io.IOException;
 import java.io.InputStreamReader;
 import javax.microedition.lcdui.*;
 import javax.microedition.midlet.MIDlet;
public class DiallNumber extends MIDlet  
 {


    private  Display display;
 private MIDlet midlet;

Form f = new form("f");



/**}
 * From MIDlet. Called when the MIDlet is started.
 */
 public void startApp()
 {

display = Display.getDisplay(this);
  display.setCurrent(f);
}





 public void pauseApp()
 {
 // No implementation required
 }

/*

 * /
 */

/**
 * From MIDlet. Called to signal the MIDlet to terminate.
 *
* @param unconditional
 * whether the MIDlet has to be unconditionally terminated
 */
 public void destroyApp(boolean unconditional)
 {
 // No implementation required
 }
   class form extends   Form  implements CommandListener
           {
           private  Command call;
            private TextField phoneField;
           private String n;
   public form(String title )
       {
       super(title);
       call =new Command("call",call.OK,0);
       this.phoneField =new TextField("number","",20,phoneField.PHONENUMBER);

   addCommand(call);
   append(this.phoneField);
   this.setCommandListener(this);
      }
        public void commandAction(Command c,Displayable  d)
       {
   if(c==call)
   {

   try
   {
       n=phoneField.getString().trim();
      platformRequest("tel:"+n);

   }
  catch(javax.microedition.io.ConnectionNotFoundException e)
  {e.printStackTrace();}
   }

   }
   }


       }

相关内容

  • 没有找到相关文章

最新更新