Friday, 2 November 2012

Call number on button click PhoneStateListener

Call number on Button click in Android and Use of Phone State Listener in Android

     This is a simple demo tutorials that will help you to understand how to call a phone number on button click.

     An Android allows you to call any phone number from your application.

For that you need to call and android intent and have to pass phone number with keyword tel: .
To get more updates about this blog click on Join This Site-->
You have to pass argument in particular format as describe below:
Here is an example code to call a number 
Intent callIntent = new Intent(Intent.ACTION_CALL);


You need to add following permission in AndroidManifest.xml

<android:name="android.permission.CALL_PHONE" />
If you like this tutorial then like us on facebook ----->

  • A Listener class that will monitor phone state, message waiting.
  • You need to override onCallStateChanged() method
  • Following are list of phone state
  • A method onCallStateChanged() will call every time when ever your device phone call state will changed. 
Here is example code for how to use PhoneStateListener

private class PhoneCallListener extends PhoneStateListener {
     String LOG_TAG = "GTUMCAlog: ";
     public void onCallStateChanged(int state, String incomingNumber) {
            if (TelephonyManager.CALL_STATE_RINGING == state) {    
// phone ringing
               Log.i(LOG_TAG, "RINGING, number: " + incomingNumber);

         if (TelephonyManager.CALL_STATE_OFFHOOK == state) {
              // active
              Log.i(LOG_TAG, "OFFHOOK");
              isPhoneCalling = true;
            if (TelephonyManager.CALL_STATE_IDLE == state) {

              Log.i(LOG_TAG, "IDLE");

                  if (isPhoneCalling) {
                       Log.i(LOG_TAG, "restart app");


GTU MCA Android Tutorial How to Call phone number from android on button click.    

Posted by:  Bhavika Jogi
Related Links
  1. Custom intermediate Progress bar demo in android. 
  2. Capture image using camera, save to sd-card and display. 
  3. Latest IT - news updates. 
  4. Free tips and tricks - Android tricks 
  5. Download free projects with Source code. 
  6. List of world celebration days.  


Post a Comment

Fill free to post your Queries and Suggesion...!

Twitter Delicious Facebook Digg Stumbleupon Favorites More

Design by Free WordPress Themes | Bloggerized by Lasantha - Premium Blogger Themes | Bluehost Review