Get Phone Type GSM/CDMA In Android Development

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

getphonetype

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

getphonetype1