Aim:
Write a program to check the state of the mobile phone using TelephonyManager API
Description
In this practical we are going to use the telephony manager class in Android. It is a powerful class. To access the state of phone. By using this class. We can elaborate the. Many functionalities. But in this practical, we will use the TelephonyManager class as they notify while we call, we receive and we hang off the call.
Process
Created project and we get the activity_main.java and MainActivity.java. So to right click on the package folder (folder in which MainActivity.java exist) created a broadcast receiver activity
Right Click > New > Other > Broadcast Receiver
The into the Broadcast Receiver file define the if else conditional statements to Print the text as per phone Ringing, Idle, and Hand off with the help of Toast
Then in the AndroidMenifest.xml which exist in manifests folder inserted uses-permission android:name="android.permission.READ_PHONE_STATE" to take the permision to use the phone activity
While creating the new Broadcast Receiver activity an new receiver tag added into the AndroidMenifest.xml file
then into the receiver tag insert a intent-filter tag and into this tag insert
Code
- AndroidManifest.xml: For permision & action for PHONE_STATE into the receiver tag
- MainActivity.java: To display the activity of and activity_main.xml file
- activity_main.xml: Design page of the MainActivity.java
- MyReceiverApp.java: To define the conditional statement with Toast to print the state of PHONE using theTelephonyManager
AndroidManifest.xml
MainActivity.java
activity_main.xml
MyReceiverApp.java
Output:
- Output on mobile phone

