get Cell Phone Id - Android Phone

Android examples for Phone:Phone Number

Description

get Cell Phone Id

Demo Code


//package com.java2s;

import android.telephony.CellLocation;
import android.telephony.TelephonyManager;
import android.telephony.cdma.CdmaCellLocation;
import android.telephony.gsm.GsmCellLocation;

public class Main {
    public static int getCellId(TelephonyManager telMan) {
        if (null == telMan) {
            return -1;
        }/*from   www  .java2 s  .  co  m*/

        CellLocation loc = telMan.getCellLocation();

        if (null == loc) {
            return -1;
        }

        if (loc instanceof CdmaCellLocation) {
            return ((CdmaCellLocation) loc).getBaseStationId();
        }

        if (loc instanceof GsmCellLocation) {
            return ((GsmCellLocation) loc).getCid();
        }

        return -1;
    }
}

Related Tutorials