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:
format: 
tel:phonenumber
Here is an example code to call a number 
Intent callIntent = new Intent(Intent.ACTION_CALL);

callIntent.setData(Uri.parse("tel:1234567890"));
startActivity(callIntent);

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 ----->
PhoneStateListener

  • A Listener class that will monitor phone state, message waiting.
  • You need to override onCallStateChanged() method
  • Following are list of phone state
    • CALL_STATE_IDLE
    • CALL_STATE_RINGING
    • CALL_STATE_OFFHOOK
       
  • 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: ";
     @Override
     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.  

8 comments:

Unknown said...

thanks for sharing this code. it is helpful for me.

Top Mobile App Development Companies India said...

Thanks for this post it's really interesting all type of art work are done by iPhone.
Very nice, keep it up.

Android Application Development

Top Mobile App Development Companies India said...

Nice blog! I loved reading through your blog. wish you good luck for your best efforts...

-----------------------------------------------------------------------------
Android Application Developer India & Android Application Development Company

Unknown said...

Nice Blog, http://claritusconsulting.com

Unknown said...

liked the post thanks for sharing
whatsapp tips and tricks

surya said...

This is extremely helpful info!! Very good work. Everything is very interesting to learn and easy to understood. Thank you for giving information. Material Design for Android

Syntrino said...

Great post very helping, Thanks for the wonderful blog through your blog...
Android App Development Company Malaysia
Custom Software Development Company Malaysia
Software Development Company Malaysia

Unknown said...

Nice blog. Thank you for sharing.
If you are looking for the best android development that will be helpful for your business.

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