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: .
format:
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
// 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
7 comments:
thanks for sharing this code. it is helpful for me.
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
Nice blog! I loved reading through your blog. wish you good luck for your best efforts...
-----------------------------------------------------------------------------
Android Application Developer India & Android Application Development Company
Nice Blog, http://claritusconsulting.com
liked the post thanks for sharing
whatsapp tips and tricks
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
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...!