This example shows how you can the phone type GSM/CDMA in android.
Algorithm:
1.) Create a new project by File-> New -> Android Project name it GetPhoneType.
2.) Write following into main.xml:
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" > <TextView android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="Your Phone Type is : " /> <TextView android:id="@+id/phonetype" android:layout_width="fill_parent" android:layout_height="wrap_content" /> </LinearLayout>
3.) Run for output.
Steps:
1.) Create a project named GetPhoneType and set the information as stated in the image.
Build Target: Android 4.4
Application Name: GetPhoneType
Package Name: com.example. GetPhoneType
Activity Name: GetPhoneTypeActivity
2.) Open GetPhoneTypeActivity.java file and write following code there:
package com.example.getphonetype; import android.app.Activity; import android.content.Context; import android.os.Bundle; import android.telephony.TelephonyManager; import android.widget.TextView; public class GetPhoneTypeActivity extends Activity { /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); TextView textPhoneType = (TextView)findViewById(R.id.phonetype); //retrieve a reference to an instance of TelephonyManager TelephonyManager telephonyManager = (TelephonyManager)getSystemService(Context.TELEPHONY_SERVICE); textPhoneType.setText(getPhoneType(telephonyManager)); } String getPhoneType(TelephonyManager phonyManager){ int phoneType = phonyManager.getPhoneType(); switch(phoneType){ case TelephonyManager.PHONE_TYPE_NONE: return "NONE"; case TelephonyManager.PHONE_TYPE_GSM: return "GSM"; case TelephonyManager.PHONE_TYPE_CDMA: return "CDMA"; default: return "UNKNOWN"; } } }
3.) Compile and build the project.
Output
Top 10 Android App Development Trends | 2020 Guide
9 Popular Cross-Platform Tools for App Development in 2019
20 Best iOS App Development Tutorials and Online Learning Resources
Top 15 Best Android Apps For C Programming | 2018 Exclusive
The Best 15 Mobile Game Development Platforms & Tools in 2018
The Top Web Development Frameworks in 2018
10 Top Web Development Frameworks In 2017
5 Best Resources to Get Started with Android Nougat