×
Namespaces

Variants
Actions
(Difference between revisions)

Making a phone call using TextField in Java ME

From Nokia Developer Wiki
Jump to: navigation, search
tanjaluodes (Talk | contribs)
m
hamishwillee (Talk | contribs)
m (Hamishwillee - Fix update timestamp in ArticleMetaData)
(25 intermediate revisions by 3 users not shown)
Line 1: Line 1:
__NOTOC__
+
[[Category:Java ME]][[Category:MIDP 2.0]][[Category:Telephony]][[Category:Code Examples]][[Category:Symbian]][[Category:Series 40]][[Category:Series 40 5th Edition (initial release)]][[Category:Series 40 6th Edition (initial release)]][[Category:Java Runtime 2.3 for Symbian]][[Category:Series 40 Developer Platform 1.0]][[Category:Symbian]][[Category:Series 40 3rd Edition (initial release)]][[Category:S60 3rd Edition (initial release)]][[Category:S60 3rd Edition FP1]][[Category:S60 3rd Edition FP2]][[Category:S60 5th Edition]][[Category:Symbian^3]][[Category:Symbian Anna]][[Category:Nokia Belle]]
__NOEDITSECTION__
+
{{Abstract|This snippet demonstrates how to make a phone call by using a {{Icode|TextField}}. The MIDlet constructs a phone number field and displays it on the screen. The user may enter a phone number into it. After that, he or she can select {{Icode|Options}} > {{Icode|Call}} to call that number.}}
{{KBCS}}
+
{{ArticleMetaData <!-- v1.2 -->
{{CodeSnippet
+
|sourcecode= [[Media:MakingPhoneCallTFSource.zip]]
|id=CS000955
+
|installfile= [[Media:MakingPhoneCallTFBinaries.zip]]
|platform=S60 3rd Edition, FP1
+
|devices= Nokia N95 8GB, Nokia 701, Nokia Asha 305
|devices=Nokia N95 8GB
+
|sdk= [http://www.developer.nokia.com/Develop/Java/Tools/ Nokia SDK 2.0 for Java],
|category=Java ME
+
|platform= Series 40, Symbian
|subcategory=Telephony
+
|devicecompatability= <!-- Compatible devices (e.g.: All* (must have GPS) ) -->
|creationdate=May 14, 2008
+
|dependencies= <!-- Any other/external dependencies e.g.: Google Maps Api v1.0 -->
|keywords=javax.microedition.lcdui.TextField
+
|signing= <!-- Empty or one of Self-Signed, DevCert, Manufacturer -->
 +
|capabilities= <!-- Capabilities required by the article/code example (e.g. Location, NetworkServices. -->
 +
|keywords= javax.microedition.midlet.MIDlet.platformRequest()
 +
|language= <!-- Language category code for non-English topics - e.g. Lang-Chinese -->
 +
|translated-by= <!-- [[User:XXXX]] -->
 +
|translated-from-title= <!-- Title only -->
 +
|translated-from-id= <!-- Id of translated revision -->
 +
|review-by= <!-- After re-review: [[User:username]] -->
 +
|review-timestamp= <!-- After re-review: YYYYMMDD -->
 +
|update-by= [[User:mtilli]]
 +
|update-timestamp= 20120703
 +
|creationdate= 20080507
 +
|author= [[User:Tapla]]
 +
<!-- The following are not in current metadata -->
 +
|id= CS000955
 
}}
 
}}
 
==Overview==
 
 
This snippet demonstrates how to make a phone call by using a <tt>TextField</tt>. The MIDlet constructs a phone number field and displays it on the screen. The user may enter a phone number into it or obtain one from the Contacts list. After that, he or she can select <tt>Options</tt> > <tt>Call</tt> to call that number.
 
  
 
==Source==
 
==Source==
  
 
<code java>
 
<code java>
 +
import javax.microedition.io.ConnectionNotFoundException;
 
import javax.microedition.lcdui.Command;
 
import javax.microedition.lcdui.Command;
 
import javax.microedition.lcdui.CommandListener;
 
import javax.microedition.lcdui.CommandListener;
Line 29: Line 40:
  
 
<code java>
 
<code java>
public class ExampleMIDlet extends MIDlet implements CommandListener {
+
public class MakingPhoneCallTF extends MIDlet implements CommandListener {
 +
    private TextField numberField;
 +
    private Command callCommand;
 
     private Command exitCommand;
 
     private Command exitCommand;
 
     private Form mainForm;
 
     private Form mainForm;
   
+
 
     /**
 
     /**
 
     * Constructor. Constructs the object and initializes displayables.
 
     * Constructor. Constructs the object and initializes displayables.
 
     */
 
     */
     public ExampleMIDlet() {
+
     public MakingPhoneCallTF() {
         mainForm = new Form("ExampleMIDlet");
+
         mainForm = new Form("Making Phone Call");
       
+
 
         // Create a phone number field, which allows a call to be made
 
         // Create a phone number field, which allows a call to be made
         mainForm.append(new TextField("Phone number", null, 20,
+
         numberField = new TextField("Phone number", null, 20, TextField.PHONENUMBER);
                TextField.PHONENUMBER));
+
        mainForm.append(numberField);
 +
 
 +
        callCommand = new Command("Call", Command.SCREEN, 0);
 +
        mainForm.addCommand(callCommand);
 
          
 
          
 
         exitCommand = new Command("Exit", Command.EXIT, 0);
 
         exitCommand = new Command("Exit", Command.EXIT, 0);
Line 47: Line 63:
 
         mainForm.setCommandListener(this);
 
         mainForm.setCommandListener(this);
 
     }
 
     }
   
+
 
     /**
 
     /**
 
     * Called when the MIDlet is started.
 
     * Called when the MIDlet is started.
Line 53: Line 69:
 
     public void startApp() {
 
     public void startApp() {
 
         Display.getDisplay(this).setCurrent(mainForm);
 
         Display.getDisplay(this).setCurrent(mainForm);
 +
    }
 +
 +
    /**
 +
    * Called when MIDlet is paused.
 +
    */
 +
    public void pauseApp() {
 
     }
 
     }
 
      
 
      
     // Other inherited methods omitted for brevity
+
     /**
    // ...
+
    * Called to signal the MIDlet to terminate.
 +
    *
 +
    * @param unconditional if true, then the MIDlet has to be unconditionally
 +
    * terminated and all resources has to be released.
 +
    */
 +
    public void destroyApp(boolean unconditional) {
 +
    }
 
      
 
      
 
     /**
 
     /**
Line 66: Line 94:
 
     */
 
     */
 
     public void commandAction(Command command, Displayable displayable) {
 
     public void commandAction(Command command, Displayable displayable) {
         if (command == exitCommand) {
+
         if (command == callCommand) {
 +
            call();
 +
        } else if (command == exitCommand) {
 
             // Exit the MIDlet
 
             // Exit the MIDlet
 
             destroyApp(true);
 
             destroyApp(true);
Line 72: Line 102:
 
         }
 
         }
 
     }
 
     }
 +
   
 +
    /**
 +
    * Makes a call to number user typed in the text field.
 +
    */
 +
    private void call() {
 +
        String number;
 +
       
 +
        number = numberField.getString();
 +
        try {           
 +
            platformRequest("tel:" + number);
 +
        } catch (ConnectionNotFoundException ex) {
 +
            System.out.println(ex.getMessage());
 +
        }
 +
    }
 +
}
 
</code>
 
</code>
  
 
==Postconditions==
 
==Postconditions==
  
A phone number field is displayed on the screen. The user can enter a phone number and select <tt>Options</tt> > <tt>Call</tt> to call that number.
+
A phone number field is displayed on the screen. The user can enter a phone number and select {{Icode|Options}} > {{Icode|Call}} to call that number.
  
 
==See also==
 
==See also==
  
* [[Making a phone call: Platform request]]
+
* [[Making a phone call programmatically using platformRequest() in Java ME]]
 
+
<!-- Translation --> [[pt:Realizando Chamadas Telefônicas Utilizando TextField]]
[[Category:Java ME]][[Category:MIDP 2.0]][[Category:Code Examples]][[Category:Telephony]][[Category:S60 3rd Edition, Feature Pack 1]][[Category:Level-Basic]][[Category:Code Snippet]]
+

Revision as of 07:57, 28 September 2012

This snippet demonstrates how to make a phone call by using a TextField. The MIDlet constructs a phone number field and displays it on the screen. The user may enter a phone number into it. After that, he or she can select Options > Call to call that number.

Article Metadata
Code ExampleTested with
Devices(s): Nokia N95 8GB, Nokia 701, Nokia Asha 305
CompatibilityArticle
Keywords: javax.microedition.midlet.MIDlet.platformRequest()
Created: tapla (07 May 2008)
Updated: mtilli (03 Jul 2012)
Last edited: hamishwillee (28 Sep 2012)

Source

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.lcdui.TextField;
import javax.microedition.midlet.MIDlet;
public class MakingPhoneCallTF extends MIDlet implements CommandListener {
private TextField numberField;
private Command callCommand;
private Command exitCommand;
private Form mainForm;
 
/**
* Constructor. Constructs the object and initializes displayables.
*/

public MakingPhoneCallTF() {
mainForm = new Form("Making Phone Call");
 
// Create a phone number field, which allows a call to be made
numberField = new TextField("Phone number", null, 20, TextField.PHONENUMBER);
mainForm.append(numberField);
 
callCommand = new Command("Call", Command.SCREEN, 0);
mainForm.addCommand(callCommand);
 
exitCommand = new Command("Exit", Command.EXIT, 0);
mainForm.addCommand(exitCommand);
mainForm.setCommandListener(this);
}
 
/**
* Called when the MIDlet is started.
*/

public void startApp() {
Display.getDisplay(this).setCurrent(mainForm);
}
 
/**
* Called when MIDlet is paused.
*/

public void pauseApp() {
}
 
/**
* Called to signal the MIDlet to terminate.
*
* @param unconditional if true, then the MIDlet has to be unconditionally
* terminated and all resources has to be released.
*/

public void destroyApp(boolean unconditional) {
}
 
/**
* 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();
} else if (command == exitCommand) {
// Exit the MIDlet
destroyApp(true);
notifyDestroyed();
}
}
 
/**
* Makes a call to number user typed in the text field.
*/

private void call() {
String number;
 
number = numberField.getString();
try {
platformRequest("tel:" + number);
} catch (ConnectionNotFoundException ex) {
System.out.println(ex.getMessage());
}
}
}

Postconditions

A phone number field is displayed on the screen. The user can enter a phone number and select Options > Call to call that number.

See also

325 page views in the last 30 days.
×