Java Code Examples for android.telephony.TelephonyManager#PHONE_TYPE_GSM

The following examples show how to use android.telephony.TelephonyManager#PHONE_TYPE_GSM . These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
private void showDeviceId() {
	AlertDialog.Builder builder = new AlertDialog.Builder(this);
	String deviceId;
	
	if (Build.VERSION.SDK_INT < 26) {
		deviceId = telephonyManager.getDeviceId();
	} else {
		switch (telephonyManager.getPhoneType()) {
		case TelephonyManager.PHONE_TYPE_GSM:
			deviceId = telephonyManager.getImei();
			break;
		case TelephonyManager.PHONE_TYPE_CDMA:
			deviceId = telephonyManager.getMeid();
			break;
		default:
			deviceId = "null";
		}
	}
	builder.setMessage(deviceId);
	builder.create().show();
}
 
Example 2
private boolean isNetworkCountryCodeAvailable() {
    // On CDMA TelephonyManager.getNetworkCountryIso() just returns SIM country.  We don't want
    // to prioritize it over location based country, so ignore it.
    final int phoneType = mTelephonyManager.getPhoneType();
    if (DEBUG) Slog.v(TAG, "    phonetype=" + phoneType);
    return phoneType == TelephonyManager.PHONE_TYPE_GSM;
}
 
Example 3
/**
 * Called from native code to request reference location info
 */
private void requestRefLocation() {
    TelephonyManager phone = (TelephonyManager)
            mContext.getSystemService(Context.TELEPHONY_SERVICE);
    final int phoneType = phone.getPhoneType();
    if (phoneType == TelephonyManager.PHONE_TYPE_GSM) {
        GsmCellLocation gsm_cell = (GsmCellLocation) phone.getCellLocation();
        if ((gsm_cell != null) && (phone.getNetworkOperator() != null)
                && (phone.getNetworkOperator().length() > 3)) {
            int type;
            int mcc = Integer.parseInt(phone.getNetworkOperator().substring(0, 3));
            int mnc = Integer.parseInt(phone.getNetworkOperator().substring(3));
            int networkType = phone.getNetworkType();
            if (networkType == TelephonyManager.NETWORK_TYPE_UMTS
                    || networkType == TelephonyManager.NETWORK_TYPE_HSDPA
                    || networkType == TelephonyManager.NETWORK_TYPE_HSUPA
                    || networkType == TelephonyManager.NETWORK_TYPE_HSPA
                    || networkType == TelephonyManager.NETWORK_TYPE_HSPAP) {
                type = AGPS_REF_LOCATION_TYPE_UMTS_CELLID;
            } else {
                type = AGPS_REF_LOCATION_TYPE_GSM_CELLID;
            }
            native_agps_set_ref_location_cellid(type, mcc, mnc,
                    gsm_cell.getLac(), gsm_cell.getCid());
        } else {
            Log.e(TAG, "Error getting cell location info.");
        }
    } else if (phoneType == TelephonyManager.PHONE_TYPE_CDMA) {
        Log.e(TAG, "CDMA not supported.");
    }
}
 
Example 4
Source Project: kcanotify   File: Util.java    License: GNU General Public License v3.0 5 votes vote down vote up
public static String getPhoneTypeName(int phoneType) {
    switch (phoneType) {
        case TelephonyManager.PHONE_TYPE_NONE:
            return "None";
        case TelephonyManager.PHONE_TYPE_GSM:
            return "GSM";
        case TelephonyManager.PHONE_TYPE_CDMA:
            return "CDMA";
        case TelephonyManager.PHONE_TYPE_SIP:
            return "SIP";
        default:
            return "Unknown";
    }
}
 
Example 5
Source Project: batteryhub   File: Phone.java    License: Apache License 2.0 5 votes vote down vote up
public static String getType(Context context) {
    TelephonyManager telManager =
            (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);

    int phoneType = telManager.getPhoneType();
    switch (phoneType) {
        case TelephonyManager.PHONE_TYPE_CDMA:
            return PHONE_TYPE_CDMA;
        case TelephonyManager.PHONE_TYPE_GSM:
            return PHONE_TYPE_GSM;
        default:
            return PHONE_TYPE_NONE;
    }
}
 
Example 6
Source Project: Mobilyzer   File: PhoneUtils.java    License: Apache License 2.0 5 votes vote down vote up
/** Returns "GSM", "CDMA". */
private String getTelephonyPhoneType() {
	switch (telephonyManager.getPhoneType()) {
	case TelephonyManager.PHONE_TYPE_CDMA:
		return "CDMA";
	case TelephonyManager.PHONE_TYPE_GSM:
		return "GSM";
	case TelephonyManager.PHONE_TYPE_NONE:
		return "None";
	}
	return "Unknown";
}
 
Example 7
private String getLAC() {
	try {
		if(tm.getPhoneType() == TelephonyManager.PHONE_TYPE_GSM) {
			GsmCellLocation gLoc = (GsmCellLocation) tm.getCellLocation();
			if(gLoc != null) {
				return Integer.toString(gLoc.getLac());
			}
		}						
	} catch(NullPointerException e) {
		Logger.e(LOG, e);
	}
	
	return null;
}
 
Example 8
private String getCellId() {	
	try {			
		String out = "";
		if (tm.getPhoneType() == TelephonyManager.PHONE_TYPE_GSM) {
			final GsmCellLocation gLoc = (GsmCellLocation) tm.getCellLocation();
			out = Integer.toString(gLoc.getCid());
		} else if(tm.getPhoneType() == TelephonyManager.PHONE_TYPE_CDMA) {
			final CdmaCellLocation cLoc = (CdmaCellLocation) tm.getCellLocation();
			out = Integer.toString(cLoc.getBaseStationId());
		}
		return out;
	} catch(NullPointerException e) {
		return null;
	}
}
 
Example 9
/**
 * @return the country from the mobile network.
 */
protected String getNetworkBasedCountry() {
    String countryIso = null;
    // TODO: The document says the result may be unreliable on CDMA networks. Shall we use
    // it on CDMA phone? We may test the Android primarily used countries.
    if (telephonyManager.getPhoneType() == TelephonyManager.PHONE_TYPE_GSM) {
        countryIso = telephonyManager.getNetworkCountryIso();
        if (!TextUtils.isEmpty(countryIso)) {
            return countryIso;
        }
    }
    return null;
}
 
Example 10
private void listing20_6() {
  String srvcName = Context.TELEPHONY_SERVICE;
  TelephonyManager telephonyManager = (TelephonyManager)getSystemService(srvcName);

  // Listing 20-6: Accessing phone-type and the device’s phone number
  String phoneTypeStr = "unknown";

  int phoneType = telephonyManager.getPhoneType();

  switch (phoneType) {
    case (TelephonyManager.PHONE_TYPE_CDMA):
      phoneTypeStr = "CDMA";
      break;
    case (TelephonyManager.PHONE_TYPE_GSM) :
      phoneTypeStr = "GSM";
      break;
    case (TelephonyManager.PHONE_TYPE_SIP):
      phoneTypeStr = "SIP";
      break;
    case (TelephonyManager.PHONE_TYPE_NONE):
      phoneTypeStr = "None";
      break;
    default: break;
  }

  Log.d(TAG, phoneTypeStr);

  // -- These require READ_PHONE_STATE uses-permission --
  int permission = ActivityCompat.checkSelfPermission(this,
    android.Manifest.permission.READ_PHONE_STATE);
  if (permission == PackageManager.PERMISSION_GRANTED) {

    // Read the IMEI for GSM or MEID for CDMA
    String deviceId = telephonyManager.getDeviceId();

    // Read the software version on the phone (note -- not the SDK version)
    String softwareVersion = telephonyManager.getDeviceSoftwareVersion();

    // Get the phone's number (if available)
    String phoneNumber = telephonyManager.getLine1Number();

    // If permission hasn't been granted, request it.
  } else {
    if (ActivityCompat.shouldShowRequestPermissionRationale(
      this, android.Manifest.permission.READ_PHONE_STATE)) {
      // TODO Display additional rationale for the requested permission.
    }
    ActivityCompat.requestPermissions(this,
      new String[]{android.Manifest.permission.READ_PHONE_STATE},
      PHONE_STATE_PERMISSION_REQUEST);
  }
}
 
Example 11
public void onCellLocationChanged(CellLocation location) {

            checkForNeighbourCount(location);
            compareLac(location);
            refreshDevice();
            mDevice.setNetID(tm);
            mDevice.getNetworkTypeName();

            switch (mDevice.getPhoneID()) {

                case TelephonyManager.PHONE_TYPE_NONE:
                case TelephonyManager.PHONE_TYPE_SIP:
                case TelephonyManager.PHONE_TYPE_GSM:
                    GsmCellLocation gsmCellLocation = (GsmCellLocation) location;
                    if (gsmCellLocation != null) {
                        //TODO @EVA where are we sending this setCellInfo data?

                        //TODO
                        /*@EVA
                            Is it a good idea to dump all cells to db because if we spot a known cell
                            with different lac then this will also be dump to db.

                        */
                        mDevice.setCellInfo(
                                gsmCellLocation.toString() +                // ??
                                mDevice.getDataActivityTypeShort() + "|" +  // No,In,Ou,IO,Do
                                mDevice.getDataStateShort() + "|" +         // Di,Ct,Cd,Su
                                mDevice.getNetworkTypeName() + "|"          // HSPA,LTE etc
                        );

                        mDevice.mCell.setLAC(gsmCellLocation.getLac());     // LAC
                        mDevice.mCell.setCID(gsmCellLocation.getCid());     // CID
                        if (gsmCellLocation.getPsc() != -1) {
                            mDevice.mCell.setPSC(gsmCellLocation.getPsc()); // PSC
                        }

                        /*
                            Add cell if gps is not enabled
                            when gps enabled lat lon will be updated
                            by function below

                         */
                    }
                    break;

                case TelephonyManager.PHONE_TYPE_CDMA:
                    CdmaCellLocation cdmaCellLocation = (CdmaCellLocation) location;
                    if (cdmaCellLocation != null) {
                        mDevice.setCellInfo(
                                cdmaCellLocation.toString() +                       // ??
                                mDevice.getDataActivityTypeShort() + "|" +  // No,In,Ou,IO,Do
                                mDevice.getDataStateShort() + "|" +         // Di,Ct,Cd,Su
                                mDevice.getNetworkTypeName() + "|"          // HSPA,LTE etc
                        );
                        mDevice.mCell.setLAC(cdmaCellLocation.getNetworkId());      // NID
                        mDevice.mCell.setCID(cdmaCellLocation.getBaseStationId());  // BID
                        mDevice.mCell.setSID(cdmaCellLocation.getSystemId());       // SID
                        mDevice.mCell.setMNC(cdmaCellLocation.getSystemId());       // MNC <== BUG!??
                        mDevice.setNetworkName(tm.getNetworkOperatorName());        // ??
                    }
            }

        }
 
Example 12
/**
 * Description:    Add entries to the "DBi_measure" DB table
 *
 * Issues:
 *                  [ ]
 *
 * Notes:           (a)
 *
 *
 * TODO:  Remove OLD notes below, once we have new ones relevant to our new table
 *
 *  From "locationinfo":
 *
 *      $ sqlite3.exe -header aimsicd.db 'select * from locationinfo;'
 *      _id|Lac|CellID|Net|Lat|Lng|Signal|Connection|Timestamp
 *      1|10401|6828xxx|10|54.67874392|25.28693531|24|[10401,6828320,126]No|Di|HSPA||2015-01-21 20:45:10
 *
 *  From "cellinfo":
 *
 *      $ sqlite3.exe -header aimsicd.db 'select * from cellinfo;'
 *      _id|Lac|CellID|Net|Lat|Lng|Signal|Mcc|Mnc|Accuracy|Speed|Direction|NetworkType|MeasurementTaken|OCID_SUBMITTED|Timestamp
 *      1|10401|6828xxx|10|54.67874392|25.28693531|24|246|2|69.0|0.0|0.0|HSPA|82964|0|2015-01-21 20:45:10
 *
 *  Issues:
 *
 */
public void onLocationChanged(Location loc) {

    DeviceApi18.loadCellInfo(tm, mDevice);

    if (!mDevice.mCell.isValid()) {
        CellLocation cellLocation = tm.getCellLocation();
        if (cellLocation != null) {
            switch (mDevice.getPhoneID()) {

                case TelephonyManager.PHONE_TYPE_NONE:
                case TelephonyManager.PHONE_TYPE_SIP:
                case TelephonyManager.PHONE_TYPE_GSM:
                    GsmCellLocation gsmCellLocation = (GsmCellLocation) cellLocation;
                    mDevice.mCell.setCID(gsmCellLocation.getCid()); // CID
                    mDevice.mCell.setLAC(gsmCellLocation.getLac()); // LAC
                    mDevice.mCell.setPSC(gsmCellLocation.getPsc()); // PSC
                    break;

                case TelephonyManager.PHONE_TYPE_CDMA:
                    CdmaCellLocation cdmaCellLocation = (CdmaCellLocation) cellLocation;
                    mDevice.mCell.setCID(cdmaCellLocation.getBaseStationId()); // BSID ??
                    mDevice.mCell.setLAC(cdmaCellLocation.getNetworkId());     // NID
                    mDevice.mCell.setSID(cdmaCellLocation.getSystemId());      // SID
                    mDevice.mCell.setMNC(cdmaCellLocation.getSystemId());      // MNC <== BUG!??

                    break;
            }
        }
    }

    if (loc != null &&  (Double.doubleToRawLongBits(loc.getLatitude()) != 0  &&  Double.doubleToRawLongBits(loc.getLongitude()) != 0)) {

        mDevice.mCell.setLon(loc.getLongitude());       // gpsd_lon
        mDevice.mCell.setLat(loc.getLatitude());        // gpsd_lat
        mDevice.mCell.setSpeed(loc.getSpeed());         // speed        // TODO: Remove, we're not using it!
        mDevice.mCell.setAccuracy(loc.getAccuracy());   // gpsd_accu
        mDevice.mCell.setBearing(loc.getBearing());     // -- [deg]??   // TODO: Remove, we're not using it!
        mDevice.setLastLocation(loc);                   //

        // Store last known location in preference
        SharedPreferences.Editor prefsEditor;
        prefsEditor = prefs.edit();
        prefsEditor.putString(context.getString(R.string.data_last_lat_lon),
                String.valueOf(loc.getLatitude()) + ":" + String.valueOf(loc.getLongitude()));
        prefsEditor.apply();

        // This only logs a BTS if we have GPS lock
        // Test: ~~Is correct behaviour? We should consider logging all cells, even without GPS.~~
        //if (mTrackingCell) {
            // This also checks that the lac are cid are not in DB before inserting
            dbHelper.insertBTS(mDevice.mCell);
        //}
    }
}
 
Example 13
public static String getCellInfo(Context ctx) throws SecurityException {
        TelephonyManager tel = (TelephonyManager) ctx.getSystemService(Context.TELEPHONY_SERVICE);

        JSONArray cellList = new JSONArray();

// Type of the network
        int phoneTypeInt = tel.getPhoneType();
        String phoneType = null;
        phoneType = phoneTypeInt == TelephonyManager.PHONE_TYPE_GSM ? "gsm" : phoneType;
        phoneType = phoneTypeInt == TelephonyManager.PHONE_TYPE_CDMA ? "cdma" : phoneType;

        //from Android M up must use getAllCellInfo
        if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.JELLY_BEAN_MR1) {

            List<CellInfo> infos = null;
            infos = tel.getAllCellInfo();

            for (int i = 0; i < infos.size(); ++i) {
                try {
                    JSONObject cellObj = new JSONObject();
                    CellInfo info = infos.get(i);
                    if (info instanceof CellInfoGsm) {
                        CellSignalStrengthGsm gsm = ((CellInfoGsm) info).getCellSignalStrength();
                        CellIdentityGsm identityGsm = ((CellInfoGsm) info).getCellIdentity();
                        cellObj.put("cellId", identityGsm.getCid());
                        cellObj.put("lac", identityGsm.getLac());
                        cellObj.put("dbm", gsm.getDbm());
                        cellList.put(cellObj);
                    } else if (info instanceof CellInfoLte) {
                        CellSignalStrengthLte lte = ((CellInfoLte) info).getCellSignalStrength();
                        CellIdentityLte identityLte = ((CellInfoLte) info).getCellIdentity();
                        cellObj.put("cellId", identityLte.getCi());
                        cellObj.put("tac", identityLte.getTac());
                        cellObj.put("dbm", lte.getDbm());
                        cellList.put(cellObj);
                    }

                } catch (Exception ex) {

                }
            }
        }


        return cellList.toString();
    }
 
Example 14
static String getTelephonyHeader() {
	// Telephony manager can tell us a few things...
	String info = "";

	if (m_telephonyManager != null) {
		try { // getDeviceId() requires android.permission.READ_PHONE_STATE
			info = "<deviceid>" + m_telephonyManager.getDeviceId() + "</deviceid>";
		} catch (Exception e1) {
			DebugTool.logError("Failure getting telephony device ID: " + e1.toString(), e1);
		}

		info = "<pt>";
		switch (m_telephonyManager.getPhoneType()) {
			case TelephonyManager.PHONE_TYPE_NONE:
				info += "NONE";
				break;
			case TelephonyManager.PHONE_TYPE_GSM:
				info += "GSM";
				break;
			case TelephonyManager.PHONE_TYPE_CDMA:
				info += "CDMA";
				break;
			default:
				info += "UNKNOWN";
		} // end-switch

		info += "</pt>" + "<nt>";

		switch (m_telephonyManager.getNetworkType()) {
			case TelephonyManager.NETWORK_TYPE_UNKNOWN:
				info += "UKNOWN";
				break;
			case TelephonyManager.NETWORK_TYPE_GPRS:
				info += "GPRS";
				break;
			case TelephonyManager.NETWORK_TYPE_EDGE:
				info += "EDGE";
				break;
			case TelephonyManager.NETWORK_TYPE_UMTS:
				info += "UMTS";
				break;
			case TelephonyManager.NETWORK_TYPE_HSDPA:
				info += "HSDPA";
				break;
			case TelephonyManager.NETWORK_TYPE_HSUPA:
				info += "HSUPA";
				break;
			case TelephonyManager.NETWORK_TYPE_HSPA:
				info += "HSPA";
				break;
			case TelephonyManager.NETWORK_TYPE_CDMA:
				info += "CDMA";
				break;
			case TelephonyManager.NETWORK_TYPE_EVDO_0:
				info += "EVDO_O";
				break;
			case TelephonyManager.NETWORK_TYPE_EVDO_A:
				info += "EVDO_A";
				break;
			case TelephonyManager.NETWORK_TYPE_1xRTT:
				info += "1xRTT";
				break;
			default:
				info += "UNKNOWN";
				break;
		} // end-switch

		info += "</nt>";
	} // end-if
	return info;
}