Pages

Showing posts with label Mobile Network Code. Show all posts
Showing posts with label Mobile Network Code. Show all posts

Monday, April 21, 2014

How to get MNC(mobile network code) and MCC(Mobile country code) in android?

Hello Friends, In this post M writing code for getting Mobile network code(MNC) and Mobile country code(MCC) in android. I using TelephonyManager class to getting MNC and MCC. No need any permission for getting this.

A mobile network code (MNC) is used in combination with a mobile country code (MCC) (also known as a "MCC / MNC tuple") to uniquely identify a mobile phone operator/carrier using the GSM/LTE, CDMA, iDEN, TETRA and UMTS public land mobile networks and some satellite mobile networks. SeeHere


1. MainActivity.java class

import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.telephony.TelephonyManager;
import android.widget.TextView;

public class MainActivity extends Activity 
{

 @Override
 protected void onCreate(Bundle savedInstanceState) 
 {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.activity_main);

  TextView txta = (TextView) findViewById(R.id.textView1);
  
  TelephonyManager tel = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
     String networkOperator = tel.getNetworkOperator();
     int mcc = 0, mnc = 0;
     if (networkOperator != null) {
         mcc = Integer.parseInt(networkOperator.substring(0, 3));
         mnc = Integer.parseInt(networkOperator.substring(3));
     }
     txta.setText("MCC : "+mcc+"\n"
       + "MNC : "+mnc);
 }
}


2. activity_main.xml

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/container"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:padding="30dp" >

    <TextView
         android:id="@+id/textView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Example code for getting Mobile network code(MNC) and mobile country code (MCC)"
        android:textSize="14sp"
        android:textStyle="bold" />

    <TextView
        android:id="@+id/textView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="10dp"
        android:text="" />

</LinearLayout>


3. ScreenShot



Download APK file Here
enjoy :)
Thank you.