Adakalanya dalam implementasi penggunaan aplikasi, kita perlu mengetahui tipe handphone yang digunakan oleh pengguna, GSM atau CDMA. Untuk mengetahui tipe handphone yang digunakan pada Android dengan cara :

Pada file AndroidManifest.xml

< ?xml version="1.0" encoding="utf-8"?>




Untuk mengetahui tipe nya dengan menggunakan Telephony Manager :

TelephonyManager telephonyManager = (TelephonyManager)getSystemService(Context.TELEPHONY_SERVICE);

Lalu pada fungsinya :

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";
  }
 }

Versi lengkapnya :

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";
  }
 }
}

Tulisan Lain   android-async-http : Library Implementasi Android Asynctask Http Client Mudah
Tagged : # #

Leave a Reply

Your email address will not be published. Required fields are marked *