Introduction

This article explains how to get information about a phone using TelePhonyManager in Android. Android Studio is used to create the sample.
This application will show all the phone details in your activity using telephonyManager. To get all the details you need to create an object of TelephonyManager. The TelePhonyManager class provides methods that will return all the details. You need to also give permission to the Android Manifest.xml file.
Methods of TelePhonyManager class
Use the following permission in the Android Manifest.xml file:
  1. <uses-permission android:name="android.permission.READ_PHONE_STATE"></uses-permission>
Step 1
Create a project like this:
imageentervalue
Step 2
Create an XML file with the following:
  1. <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
  2. xmlns:tools="http://schemas.android.com/tools"
  3. android:layout_width="match_parent"
  4. android:layout_height="match_parent"
  5. android:paddingLeft="@dimen/activity_horizontal_margin"
  6. android:paddingRight="@dimen/activity_horizontal_margin"
  7. android:paddingTop="@dimen/activity_vertical_margin"
  8. android:paddingBottom="@dimen/activity_vertical_margin"
  9. tools:context=".MainActivity">
  10. <TextView
  11. android:id="@+id/textView"
  12. android:layout_width="wrap_content"
  13. android:layout_height="wrap_content"
  14. android:textSize="15dp"
  15. android:text="Phone Details"
  16. android:layout_centerHorizontal="true"
  17. />
  18. </RelativeLayout>
Step 3
Create a Java file with the following.
In this, you will create a TelePhonyManager object and call the methods regarding the details you want to show on the activity.
  1. package com.androidtelephonymanagerexample;
  2. import android.content.Context;
  3. import android.os.Bundle;
  4. import android.app.Activity;
  5. import android.telephony.TelephonyManager;
  6. import android.view.Menu;
  7. import android.widget.TextView;
  8. public class MainActivity extends Activity {
  9. TextView textView;
  10. String setType;
  11. @Override
  12. protected void onCreate(Bundle savedInstanceState) {
  13. super.onCreate(savedInstanceState);
  14. setContentView(R.layout.activity_main);
  15. textView = (TextView) findViewById(R.id.textView);
  16. TelephonyManager telephonyManager = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
  17. String deviceId = telephonyManager.getDeviceId();
  18. String simSerialNumber = telephonyManager.getSimSerialNumber();
  19. String networkCountryIso = telephonyManager.getNetworkCountryIso();
  20. String simCountryIso = telephonyManager.getSimCountryIso();
  21. String deviceSoftwareVersion = telephonyManager.getDeviceSoftwareVersion();
  22. String voiceMailNumber = telephonyManager.getVoiceMailNumber();
  23. String simOperatorName = telephonyManager.getSimOperatorName();
  24. int networkType = telephonyManager.getNetworkType();
  25. if(telephonyManager.getPhoneType()==1)
  26. {
  27. setType="GSM";
  28. }
  29. textView.setText("deviceid:" + deviceId + "" + "\n simSerialNumber:" + simSerialNumber + "" + " \n networkCountryIso :" + networkCountryIso + "" + "\n simCountryIso :" + simCountryIso +
  30. "" + "\n deviceSoftwareVersion :" + deviceSoftwareVersion + "" + "\n voiceMailNumber :" + voiceMailNumber + "" + "\nNetworkType: " + networkType + "" + "\nsimOperatorName: " +
  31. simOperatorName+""+"\nphoneType:"+setType+""+"\nnetworkType:"+networkType);
  32. }
  33. @Override
  34. public boolean onCreateOptionsMenu(Menu menu) {
  35. // Inflate the menu; this adds items to the action bar if it is present.
  36. getMenuInflater().inflate(R.menu.main, menu);
  37. return true;
  38. }
  39. }
Step 4
Provide the following permission in the Android Manifest.xml file:
  1. <?xml version="1.0" encoding="utf-8"?>
  2. <manifest xmlns:android="http://schemas.android.com/apk/res/android"
  3. package="com.androidtelephonymanagerexample"
  4. android:versionCode="1"
  5. android:versionName="1.0" >
  6. <uses-sdk
  7. android:minSdkVersion="7"
  8. android:targetSdkVersion="16" />
  9. <application
  10. android:allowBackup="true"
  11. android:icon="@drawable/ic_launcher"
  12. android:label="@string/app_name"
  13. android:theme="@style/AppTheme" >
  14. <activity
  15. android:name="com.androidtelephonymanagerexample.MainActivity"
  16. android:label="@string/app_name" >
  17. <intent-filter>
  18. <action android:name="android.intent.action.MAIN" />
  19. <category android:name="android.intent.category.LAUNCHER" />
  20. </intent-filter>
  21. </activity>
  22. </application>
  23. <uses-permission android:name="android.permission.READ_PHONE_STATE"></uses-permission>
  24. </manifest>
Step 5
All the details regarding the phone:
image which show daata