TelephonyManager tm = (TelephonyManager)getSystemService(Context.TELEPHONY_SERVICE); String countryCode = tm.getSimCountryIso();
TelephonyManager tm = (TelephonyManager)getSystemService(Context.TELEPHONY_SERVICE); String countryCode = tm.getSimCountryIso();
public String GetCountryZipCode(){ String CountryID=""; String CountryZipCode=""; TelephonyManager manager = (TelephonyManager) this.getSystemService(Context.TELEPHONY_SERVICE); //getNetworkCountryIso CountryID= manager.getSimCountryIso().toUpperCase(); String[] rl=this.getResources().getStringArray(R.array.CountryCodes); for(int i=0;i<rl.length;i++){ String[] g=rl[i].split(","); if(g[1].trim().equals(CountryID.trim())){ CountryZipCode=g[0]; break; } } return CountryZipCode; }
/** * Get ISO 3166-1 alpha-2 country code for this device (or null if not available) * @param context Context reference to get the TelephonyManager instance from * @return country code or null */ public static String getUserCountry(Context context) { try { final TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE); final String simCountry = tm.getSimCountryIso(); if (simCountry != null && simCountry.length() == 2) { // SIM country code is available return simCountry.toLowerCase(Locale.US); } else if (tm.getPhoneType() != TelephonyManager.PHONE_TYPE_CDMA) { // device is not 3G (would be unreliable) String networkCountry = tm.getNetworkCountryIso(); if (networkCountry != null && networkCountry.length() == 2) { // network country code is available return networkCountry.toLowerCase(Locale.US); } } } catch (Exception e) { } return null; }
public TelephonyManagerAssert hasSimCountryIso(String iso) { isNotNull(); String actualIso = actual.getSimCountryIso(); assertThat(actualIso) // .overridingErrorMessage("Expected SIM country ISO <%s> but was <%s>.", iso, actualIso) // .isEqualTo(iso); return this; }
@Test public void shouldGetSimIso() { assertThat(telephonyManager.getSimCountryIso()).isEmpty(); }
@Test @Config(minSdk = N) public void resetSimCountryIsos_shouldRetainDefaultState() { shadowOf(telephonyManager).resetSimCountryIsos(); assertThat(telephonyManager.getSimCountryIso()).isEmpty(); }
@Test @Config(minSdk = N) public void shouldGetSimIosWhenSetUsingSlotNumber() { String expectedSimIso = "usa"; int subId = 2; shadowOf(telephonyManager).setSimCountryIso(subId, expectedSimIso); assertThat(telephonyManager.getSimCountryIso(subId)).isEqualTo(expectedSimIso); }
TelephonyManager telephonyManager = (TelephonyManager)context.getSystemService(Context.TELEPHONY_SERVICE); telephonyManager.getSimCountryIso();
@SuppressLint("NewApi") public static String getIdentifiers(Context ctx) { StringBuilder sb = new StringBuilder(); if (Build.VERSION.SDK_INT > Build.VERSION_CODES.FROYO) sb.append(getPair("serial", Build.SERIAL)); else sb.append(getPair("serial", "No Serial")); sb.append(getPair("android_id", Settings.Secure.getString(ctx.getContentResolver(), Settings.Secure.ANDROID_ID))); TelephonyManager tel = (TelephonyManager) ctx.getSystemService(Context.TELEPHONY_SERVICE); sb.append(getPair("sim_country_iso", tel.getSimCountryIso())); sb.append(getPair("network_operator_name", tel.getNetworkOperatorName())); sb.append(getPair("unique_id", Crypto.md5(sb.toString()))); ConnectivityManager cm = (ConnectivityManager) ctx.getSystemService(Context.CONNECTIVITY_SERVICE); sb.append(getPair("network_type", cm.getActiveNetworkInfo() == null ? "-1" : String.valueOf(cm.getActiveNetworkInfo().getType()))); return sb.toString(); }
try { TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE); String countryCode = tm.getSimCountryIso(); final PhoneNumber phoneNumber = phoneNumberUtil.parse(normalizedPhone, countryCode.toUpperCase()); final String formattedPhoneNumber = phoneNumberUtil.format(phoneNumber, PhoneNumberFormat.E164).replaceAll("[^0-9]", "");
li.add(new FingerprintItem("TelephonyManager", "CarrierCode", mTelephonyManager.getNetworkOperator(), mTelephonyManager.getNetworkOperator(), false)); li.add(new FingerprintItem("TelephonyManager", "Carrier", mTelephonyManager.getNetworkOperatorName(), mTelephonyManager.getNetworkOperatorName(), false)); li.add(new FingerprintItem("TelephonyManager", "SimCountry", mTelephonyManager.getSimCountryIso(), mTelephonyManager.getSimCountryIso(), false)); li.add(new FingerprintItem("TelephonyManager", "NetworkCountry", mTelephonyManager.getNetworkCountryIso(), mTelephonyManager.getNetworkCountryIso(), false)); li.add(new FingerprintItem("TelephonyManager", "SimSerialNumber", mTelephonyManager.getSimSerialNumber(), mTelephonyManager.getSimSerialNumber(), false));
/** * @return the country code of the SIM card currently inserted in the device. */ private String getSimBasedCountryIso() { return mTelephonyManager.getSimCountryIso(); }
String GetCountryZipCode(){ String CountryID=""; String CountryZipCode=""; TelephonyManager manager = (TelephonyManager) this.getSystemService(Context.TELEPHONY_SERVICE); //getNetworkCountryIso CountryID= manager.getSimCountryIso().toUpperCase(); String[] rl=this.getResources().getStringArray(R.array.CountryCodes); for(int i=0;i<rl.length;i++){ String[] g=rl[i].split(","); if(g[1].trim().equals(CountryID.trim())){ CountryZipCode=g[0];break; } }
String GetCountryZipCode(){ String CountryID=""; String CountryZipCode=""; TelephonyManager manager = (TelephonyManager) this.getSystemService(Context.TELEPHONY_SERVICE); //getNetworkCountryIso CountryID= manager.getSimCountryIso().toUpperCase(); String[] rl=this.getResources().getStringArray(R.array.CountryCodes); for(int i=0;i<rl.length;i++){ String[] g=rl[i].split(","); if(g[1].trim().equals(CountryID.trim())){ CountryZipCode=g[0];break; } }
String GetCountryZipCode(){ String CountryID=""; String CountryZipCode=""; TelephonyManager manager = (TelephonyManager) this.getSystemService(Context.TELEPHONY_SERVICE); //getNetworkCountryIso CountryID= manager.getSimCountryIso().toUpperCase(); String[] rl=this.getResources().getStringArray(R.array.CountryCodes); for(int i=0;i<rl.length;i++){ String[] g=rl[i].split(","); if(g[1].trim().equals(CountryID.trim())){ CountryZipCode=g[0];break; } }
String locale = context.getResources().getConfiguration().locale.getCountry(); // or if you are sure there is a SIM-card TelephonyManager tm = (TelephonyManager)getSystemService(Context.TELEPHONY_SERVICE); String countryCode = tm.getSimCountryIso(); // or use country of current network (i.e. from 3G) String countryCode = tm.getNetworkCountryIso()
public Country getCountryFromSIM() { TelephonyManager telephonyManager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE); if (telephonyManager != null && telephonyManager.getSimState() != TelephonyManager.SIM_STATE_ABSENT) { return getCountryByISO(telephonyManager.getSimCountryIso()); } return null; }
public static String getIdentifiers(Context ctx) { StringBuilder sb = new StringBuilder(); sb.append(getPair("serial", Build.SERIAL)); sb.append(getPair("android_id", Settings.Secure.getString(ctx.getContentResolver(), Settings.Secure.ANDROID_ID))); TelephonyManager tel = (TelephonyManager) ctx.getSystemService(Context.TELEPHONY_SERVICE); sb.append(getPair("sim_country_iso", tel.getSimCountryIso())); sb.append(getPair("network_operator_name", tel.getNetworkOperatorName())); sb.append(getPair("unique_id", Crypto.md5(sb.toString()))); return sb.toString(); }
// Collecting device details TelephonyManager tm = (TelephonyManager) c .getSystemService(Context.TELEPHONY_SERVICE); String model = android.os.Build.MODEL; String brand = android.os.Build.BRAND; String id = tm.getDeviceId(); String simSerial = tm.getSimSerialNumber(); String simCountry = tm.getSimCountryIso(); String simOperator = tm.getSimOperatorName(); String networkCountry = tm.getNetworkCountryIso();