本文整理了Java中android.telephony.TelephonyManager.getNetworkCountryIso()
方法的一些代码示例,展示了TelephonyManager.getNetworkCountryIso()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。TelephonyManager.getNetworkCountryIso()
方法的具体详情如下:
包路径:android.telephony.TelephonyManager
类名称:TelephonyManager
方法名:getNetworkCountryIso
暂无
代码示例来源:origin: stackoverflow.com
TelephonyManager tm = (TelephonyManager)this.getSystemService(this.TELEPHONY_SERVICE);
String countryCodeValue = tm.getNetworkCountryIso();
代码示例来源:origin: google/ExoPlayer
/**
* Returns the upper-case ISO 3166-1 alpha-2 country code of the current registered operator's MCC
* (Mobile Country Code), or the country code of the default Locale if not available.
*
* @param context A context to access the telephony service. If null, only the Locale can be used.
* @return The upper-case ISO 3166-1 alpha-2 country code, or an empty String if unavailable.
*/
public static String getCountryCode(@Nullable Context context) {
if (context != null) {
TelephonyManager telephonyManager =
(TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
if (telephonyManager != null) {
String countryCode = telephonyManager.getNetworkCountryIso();
if (!TextUtils.isEmpty(countryCode)) {
return toUpperInvariant(countryCode);
}
}
}
return toUpperInvariant(Locale.getDefault().getCountry());
}
代码示例来源:origin: stackoverflow.com
/**
* 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;
}
代码示例来源:origin: square/assertj-android
public TelephonyManagerAssert hasNetworkCountryIso(String iso) {
isNotNull();
String actualIso = actual.getNetworkCountryIso();
assertThat(actualIso) //
.overridingErrorMessage("Expected network country ISO <%s> but was <%s>.", iso,
actualIso) //
.isEqualTo(iso);
return this;
}
代码示例来源:origin: JZ-Darkal/AndroidHttpCapture
_ISOCountryCode = _telManager.getNetworkCountryIso();
代码示例来源:origin: robolectric/robolectric
@Test
public void shouldGiveNetworkCountryIso() {
shadowOf(telephonyManager).setNetworkCountryIso("SomeIso");
assertEquals("SomeIso", telephonyManager.getNetworkCountryIso());
}
代码示例来源:origin: ac-pm/Inspeckage
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));
代码示例来源:origin: stackoverflow.com
/**
* network iso code: referred and listed at:
* http://en.wikipedia.org/wiki/List_of_mobile_country_codes
*/
TelephonyManager manager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
Constants.DEVICE_COUNTRY = manager.getNetworkCountryIso();
代码示例来源:origin: stackoverflow.com
/**
* network iso code: referred and listed at:
* http://en.wikipedia.org/wiki/List_of_mobile_country_codes
*/
TelephonyManager manager = (TelephonyManager) getApplicationContext().getSystemService(Context.TELEPHONY_SERVICE);
String DEVICE_COUNTRY = manager.getNetworkCountryIso();
代码示例来源:origin: stackoverflow.com
String iso = null ;
TelephonyManager telephonyManager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
// Get network country iso
if (telephonyManager.getNetworkCountryIso() != null
&& !telephonyManager.getNetworkCountryIso().toString().equals(""))
{
iso = telephonyManager.getNetworkCountryIso().toString();
}
代码示例来源:origin: geniusgithub/AndroidDialer
/**
* @return the country code of the current telephony network the user is connected to.
*/
private String getNetworkBasedCountryIso() {
return mTelephonyManager.getNetworkCountryIso();
}
代码示例来源:origin: stackoverflow.com
TelephonyManager tm = (TelephonyManager)getSystemService(getApplicationContext().TELEPHONY_SERVICE);
String countryCode = tm.getNetworkCountryIso();
代码示例来源:origin: stackoverflow.com
TelephonyManager teleMgr = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
String localeCountry = teleMgr.getNetworkCountryIso();
if (localeCountry != null) {
Locale loc = new Locale("",localeCountry);
Log.d(TAG, "User is from " + loc);
}
代码示例来源:origin: stackoverflow.com
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()
代码示例来源:origin: stackoverflow.com
TelephonyManager tel = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
String networkOperator = tel.getNetworkOperator();
String countryCode = tel.getNetworkCountryIso();
if (TextUtils.isEmpty(networkOperator) == false) {
int mcc = Integer.parseInt(networkOperator.substring(0, 3));
int mnc = Integer.parseInt(networkOperator.substring(3));
}
代码示例来源:origin: stackoverflow.com
TelephonyManager tm = (TelephonyManager) getActivity()
.getSystemService(Context.TELEPHONY_SERVICE);
String countryISOCode = tm.getNetworkCountryIso().toUpperCase(Locale.US);
if (countryISOCode.isEmpty()) { // when not connected fall back to the SIM's country
countryISOCode = tm.getSimCountryIso().toUpperCase(Locale.US);
}
if (countryISOCode.isEmpty()) { // when even no SIM, get the countrycode from the locale
countryISOCode = Locale.getDefault().getCountry();
}
代码示例来源:origin: stackoverflow.com
TelephonyManager tm = (TelephonyManager)getSystemService(Context.TELEPHONY_SERVICE);
// Will work on all networks. Only provide the SIM card's country
String countryCode = tm.getSimCountryIso();
// Might not work well on CDMA networks. Will provide the country code
// for the country the device is currently in.
String currentCountryCode = tm.getNetworkCountryIso();
代码示例来源:origin: com.squareup.assertj/assertj-android
public TelephonyManagerAssert hasNetworkCountryIso(String iso) {
isNotNull();
String actualIso = actual.getNetworkCountryIso();
assertThat(actualIso) //
.overridingErrorMessage("Expected network country ISO <%s> but was <%s>.", iso,
actualIso) //
.isEqualTo(iso);
return this;
}
代码示例来源:origin: antest1/kcanotify
public static boolean isInternational(Context context) {
TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
return (tm != null && tm.getSimCountryIso() != null && !tm.getSimCountryIso().equals(tm.getNetworkCountryIso()));
}
代码示例来源:origin: stackoverflow.com
// 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();
内容来源于网络,如有侵权,请联系作者删除!