Android tutorial - make phone call - android app development - android studio - android development tutorial
Definition of phone call in Android:
- Android provides Built-in applications for phone calls, in some occasions we may need to make a phone call through our application.
- This could easily be done by using implicit Intent with appropriate actions.
- Also, we can use PhoneStateListener and TelephonyManager classes, in order to monitor the changes in some telephony states on the device.
- We show you how to make a phone call in Android, and monitor the phone call states via PhoneStateListener.
1 Android Layout Files
- Simple layout file, to display a button.
- File: res/layout/main.xml
2. Activity
- Use below code snippet to make a phone call in Android.
- File: MainActivity.java - When the button is call, make a phone to 0377778888.
3) Android Manifest
- To make a phone call, Android need CALL_PHONE permission.
- File: AndroidManifest.xml
4) PhoneStateListener example
- Ok, now we update the above activity, to monitor the phone call states, when a phone call is ended, come back to the original activity (actually, it just restarts the activity).
- Read comment, it should be self-explanatory.
Note :
- Run it and refer to the logcat console to understand how PhoneStateListener works.
- File: MainActivity.java
- Update Android Manifest file again, PhoneStateListener need READ_PHONE_STATE permission.
- File: AndroidManifest.xml
5) Demo - android emulator - android tutorial
- Activity started, just display a button.
- When button is clicked, make a phone call to 0377778888.
- When phone call is hang out or ended, restart the main activity.