Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to know Location Area Code and Cell ID in android phone

Tags:

android

I would like to know Location Area Code and Cell ID saved in sim card.

How to get Location Area Code and Cell ID in android phone.

best regards.

like image 882
user368916 Avatar asked Nov 11 '10 08:11

user368916


People also ask

What is a cell ID number?

A GSM Cell ID (CID) is a generally unique number used to identify each base transceiver station (BTS) or sector of a BTS within a location area code (LAC) if not within a GSM network.

What is Location Area Code in GSM?

Location Area Code is composed of a three decimal digit Mobile Country Code (MCC), a two to three digit Mobile Network Code (MNC) that identifies a Subscriber Module Public Land Mobile Network (SM PLMN) in that country, and a Location Area Code (LAC) which is a 16 bit number with two special values, thereby allowing ...

What is cell ID MCC MNC LAC?

Cell Global Identity (CGI) is a globally unique identifier for a Base Transceiver Station in mobile phone networks. It consists of four parts: Mobile Country Code (MCC), Mobile Network Code (MNC), Location Area Code (LAC) and Cell Identification (CI).


2 Answers

Type in *#*#4636#*#* into the dialer and that might be what you're looking for.

like image 115
android Avatar answered Sep 21 '22 10:09

android


This Is not easier, because you must know what you are dealing with. First u must be know what is this. Like android documentation say..

I TRANSLATED SOME KOTLIN SCRIPTS TO JAVA BUT NOT ALL. DON'T WORRY, JAVA IS EASY TO TRANSLATE TO KOTLIN AND MAKE REVERSE.

TelephonyManager Provides access to information about the telephony services on the device. Applications can use the methods in this class to determine telephony services and states, as well as to access some types of subscriber information. Applications can also register a listener to receive notification of telephony state changes.

This will take you to TELEPHONY_SERVICE

Use with getSystemService(String) to retrieve a TelephonyManager for handling management the telephony features of the device.*

Kotlin

val telephonyManager = getSystemService(Context.TELEPHONY_SERVICE) as TelephonyManager

java

   final TelephonyManager telephony = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);

After that you find this

Kotlin

val cellLocation = telephonyManager.allCellInfo

java

   List<CellInfo> cellLocation = telephonyManager.getAllCellInfo();

getAllCellInfo

Returns all observed cell information from all radios on the device including the primary and neighboring cells. Calling this method does not trigger a call to onCellInfoChanged(), or change the rate at which onCellInfoChanged() is called.

The list can include one or more CellInfoGsm, CellInfoCdma, CellInfoLte, and CellInfoWcdma objects, in any combination.

The information says that you can obtain the respective type of network in which your device and / or sim card belong

Kotlin

   if (cellLocation != null) {  //verify if is'nt null
        for (info in cellLocation) {    // Loop for go through Muteablelist
            if (info is CellInfoGsm) {  //verify if Network is Gsm type

                // val gsm = (info as CellInfoGsm).cellSignalStrength  //get the cell Signal strength  
                val identityGsm = (info as CellInfoGsm).cellIdentity   //get the cellIdentity data 
                val defineTextLAC = getString(R.string.lac, "lola"+identityGsm.lac)  //get the LAC(LOCATION AREA CODE) string
                lacLabel.text = defineTextLAC   //set the xml text in element textview

            }else if(info is CellInfoCdma){     //verify if Network is Cdma type

                val identityCdma = info.cellIdentity    //get the cellIdentity data 
                val defineTextLAC = getString(R.string.lac, "lola"+identityCdma.basestationId)   //get the (basestationId) string
                lacLabel.text = defineTextLAC   //set the xml text in element textview      //get the LAC(LOCATION AREA CODE) string

            }else if(info is CellInfoLte){       //verify if Network is LTE type

                val identityLte = info.cellIdentity     //get the cellIdentity data
                val defineTextLAC = getString(R.string.lac, "pop"+identityLte.ci)       //get the CI(CellIdentity) string
                lacLabel.text = defineTextLAC  //set the xml text in element textview

            }else if  (lCurrentApiVersion >= Build.VERSION_CODES.JELLY_BEAN_MR2 && info is CellInfoWcdma) { //verify if Network is Wcdma and version SFK match with te network type

                val identityWcdma = info.cellIdentity       //get the cellIdentity data
                val defineTextLAC = getString(R.string.lac, "lola"+identityWcdma.cid) //  get the Cid(CellIdentity) string  
                lacLabel.text = defineTextLAC  //set the xml text in element textview

            }
        }
    }

As you can see you can obtain diferent propieties for respective network type for example GSM

java

   getCid(), getLac(), getMccString(), getBsic(), getMncString()

or for LTE

java

 getEarfcn(), getMccString(), getMncString(), getCi(), getPci(), getTac() 

Now, that's right! The problem is when in the LOG you begin to see MAX_VALUES Int data type in this case 2147483647. In the documentation say "16-bit Tracking Area Code, Integer.MAX_VALUE if unknown" Then the app say 2147483647 and we jump out of the window.

But, if we think deeping we're doing this just one time. we're get the property network one time. We should update when the status network proprietary change, and this is named Listener

Kotlin

private var signalStrengthListener: SignalStrengthListener? = null

       signalStrengthListener = SignalStrengthListener()

   (getSystemService(Context.TELEPHONY_SERVICE) as TelephonyManager).listen(signalStrengthListener, 
  PhoneStateListener.LISTEN_SIGNAL_STRENGTHS)

    tm = getSystemService(Context.TELEPHONY_SERVICE) as TelephonyManager

to make class and extend PhoneStateListener class

Kotlin

   private inner class SignalStrengthListener() : PhoneStateListener() {



    override fun onSignalStrengthsChanged(signalStrength: android.telephony.SignalStrength) {

   **//to do in listener... in the below link**

   }
 }

This is the java example for make the listener content and other function to help our

The next code is some simple and silly because the listener is working, Listen. And the network proprietary data type change so fast that we can't see that. But the only thing to do is the next script

  if(cellInfo.cellIdentity.tac != 2147483647){   //2147483647 is the MAX_VALUE INT DATA TYPE
            cellTac =  cellInfo.cellIdentity.tac  //tac is a propiety network (TRACKING AREA CODE**strong text**
   }

so, it only changes when you get a known value

I leave some links to know most about it

Example of app in prod

Java examples android

Java example android

like image 31
Walter Palacios Avatar answered Sep 24 '22 10:09

Walter Palacios