Practical 5 : Android TelephonyManager API check state mobile phone - IndianTechnoEra
Latest update Android YouTube

Practical 5 : Android TelephonyManager API check state mobile phone

Android TelephonyManager API

 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 tag and put …action.PHONE_STATE type value.

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

Post a Comment

Feel free to ask your query...
Cookie Consent
We serve cookies on this site to analyze traffic, remember your preferences, and optimize your experience.
Oops!
It seems there is something wrong with your internet connection. Please connect to the internet and start browsing again.
AdBlock Detected!
We have detected that you are using adblocking plugin in your browser.
The revenue we earn by the advertisements is used to manage this website, we request you to whitelist our website in your adblocking plugin.
Site is Blocked
Sorry! This site is not available in your country.