×
Namespaces

Variants
Actions
(Difference between revisions)

Making a phone call programmatically using platformRequest() in Java ME

From Nokia Developer Wiki
Jump to: navigation, search
Forum Nokia KB (Talk | contribs)
hamishwillee (Talk | contribs)
m (Hamishwillee - Adding missing translation link)
(28 intermediate revisions by 8 users not shown)
Line 1: Line 1:
__NOTOC__
+
[[Category:Java ME]][[Category:Telephony]][[Category:MIDP 2.0]][[Category:Code Examples]][[Category:Series 40 5th Edition (initial release)]][[Category:Series 40 6th Edition (initial release)]][[Category:Symbian]][[Category:Series 40 3rd Edition (initial release)]][[Category:Series 40 Developer Platform 1.0]][[Category:Java Runtime 2.3 for Symbian]][[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__
+
{{ArticleMetaData <!-- v1.2 -->
 
+
|sourcecode= [[Media:MakingPhoneCall-Java.zip]]
{|style="background:#eceff2" width="660px" border="1" cellpadding="5" cellspacing="0"
+
|installfile= [[Media:MakingPhoneCallBinaries.zip]]
|-
+
|devices= Nokia N95 8GB, Nokia 701, Nokia Asha 305
|'''ID''' || &nbsp;
+
|sdk= [http://www.developer.nokia.com/Develop/Java/Tools/ Nokia SDK 2.0 for Java],
|'''Creation date''' || May 7, 2008
+
|platform= Series 40, Symbian
|-
+
|devicecompatability= <!-- Compatible devices (e.g.: All* (must have GPS) ) -->
|'''Platform''' || S60 3rd Edition, FP1
+
|dependencies= <!-- Any other/external dependencies e.g.: Google Maps Api v1.0 -->
|'''Tested on devices''' || Nokia N95 8GB
+
|signing= <!-- Empty or one of Self-Signed, DevCert, Manufacturer -->
|-
+
|capabilities= <!-- Capabilities required by the article/code example (e.g. Location, NetworkServices. -->
|'''Category''' || Java ME
+
|keywords= javax.microedition.midlet.MIDlet.platformRequest()
|'''Subcategory''' || Telephony
+
|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 -->
{|style="background:#eceff2" width="660px" border="1" cellpadding="5" cellspacing="0"
+
|review-by= <!-- After re-review: [[User:username]] -->
|-
+
|review-timestamp= <!-- After re-review: YYYYMMDD -->
|'''Keywords (APIs, classes, methods, functions):''' javax.microedition.midlet.MIDlet, javax.microedition.midlet.MIDlet.platformRequest()
+
|update-by= <!-- After significant update: [[User:username]]-->
|}
+
|update-timestamp= <!-- After significant update: YYYYMMDD -->
 
+
|creationdate= 20080507
 +
|author= [[User:Tapla]]
 +
<!-- The following are not in current metadata -->
 +
|id= CS000956
 +
}}
 
==Overview==
 
==Overview==
  
This snippet demonstrates how to make a phone call by using a platform request. The MIDlet constructs a menu item through which the user can call the specified number. After the platform request has been made, the user is prompted whether he or she wants to make a voice call, a video call or an Internet call.
+
{{Abstract|This snippet demonstrates how to make a phone call by using a platform request.}} The MIDlet constructs a menu item through which the user can call the specified number. After the platform request has been made, the user is prompted whether he or she wants to make a voice call, a video call, or an Internet call.
  
 
==Source==
 
==Source==
Line 41: Line 45:
 
     private Command exitCommand;
 
     private Command exitCommand;
 
     private Form mainForm;
 
     private Form mainForm;
    // The phone number to call
 
    private final String PHONE_NUMBER = "0700123123";
 
 
      
 
      
 +
    // The phone number to call
 +
    private final String PHONE_NUMBER = "123456789";
 +
 
     /**
 
     /**
 
     * Constructor. Constructs the object and initializes displayables.
 
     * Constructor. Constructs the object and initializes displayables.
Line 49: Line 54:
 
     public ExampleMIDlet() {
 
     public ExampleMIDlet() {
 
         mainForm = new Form("ExampleMIDlet");
 
         mainForm = new Form("ExampleMIDlet");
       
+
 
         callCommand = new Command("Call", Command.SCREEN, 0);
 
         callCommand = new Command("Call", Command.SCREEN, 0);
 
         mainForm.addCommand(callCommand);
 
         mainForm.addCommand(callCommand);
       
+
 
         exitCommand = new Command("Exit", Command.EXIT, 0);
 
         exitCommand = new Command("Exit", Command.EXIT, 0);
 
         mainForm.addCommand(exitCommand);
 
         mainForm.addCommand(exitCommand);
       
+
 
         mainForm.setCommandListener(this);
 
         mainForm.setCommandListener(this);
 
     }
 
     }
   
+
 
     /**
 
     /**
 
     * Calls the specified number.
 
     * Calls the specified number.
Line 66: Line 71:
 
             platformRequest("tel:" + number);
 
             platformRequest("tel:" + number);
 
         } catch (ConnectionNotFoundException ex) {
 
         } catch (ConnectionNotFoundException ex) {
             // TODO: Exception handling
+
             System.out.println(ex.getMessage());
 
         }
 
         }
 
     }
 
     }
   
+
 
     /**
 
     /**
 
     * Called when the MIDlet is started.
 
     * Called when the MIDlet is started.
Line 75: Line 80:
 
     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) {
 +
    }   
 +
 
     /**
 
     /**
 
     * From CommandListener.
 
     * From CommandListener.
Line 96: Line 113:
 
         }
 
         }
 
     }
 
     }
 +
}
 
</code>
 
</code>
  
 
==Postconditions==
 
==Postconditions==
  
The user may select <tt>Call</tt> to call the specified number. He or she may also select whether the call should be a voice call, a video call or an Internet call.
+
The user can select {{Icode|Call}} to call the specified number. He or she may also select whether the call should be a voice call, a video call, or an Internet call.
  
 
==See also==
 
==See also==
  
* [[Making a phone call: TextField]]
+
* [[Archived:Making a phone call using TextField in Java ME]]
 
+
<!-- Translation --> [[pt:Realizando Chamadas Telefônicas a partir de platformRequest()]]
[[Category:Java ME]][[Category:MIDP 2.0]][[Category:Code Examples]][[Category:Telephony]]
+

Revision as of 08:55, 18 September 2012

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)
Last edited: hamishwillee (18 Sep 2012)

Contents

Overview

This snippet demonstrates how to make a phone call by using a platform request. The MIDlet constructs a menu item through which the user can call the specified number. After the platform request has been made, the user is prompted whether he or she wants to make a voice call, a video call, or an Internet call.

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.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) {
System.out.println(ex.getMessage());
}
}
 
/**
* 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(PHONE_NUMBER);
} else if (command == exitCommand) {
// Exit the MIDlet
destroyApp(true);
notifyDestroyed();
}
}
}

Postconditions

The user can select Call to call the specified number. He or she may also select whether the call should be a voice call, a video call, or an Internet call.

See also

373 page views in the last 30 days.
×