获取国家 TelephonyManager 与 locale.getCountry()
Get country TelephonyManager vs locale.getCountry()
有什么区别:
String locale = context.getResources().getConfiguration().locale.getCountry();
和
TelephonyManager tm = (TelephonyManager)this.getSystemService(this.TELEPHONY_SERVICE);
String countryCodeValue = tm.getNetworkCountryIso();
我需要的是这样的(很难测试)。用户来自美国,带着他的 sim 卡去法国旅行,并在国外使用他的 sim 卡,设备一直是英语(美国)。当他到达法国时,我需要从代码中获取法国。怎么做才对?
使用TelephonyManager.getNetworkCountryIso()
Returns the ISO country code equivalent of the current registered operator's MCC (Mobile Country Code).
Availability: Only when user is registered to a network. Result may be unreliable on CDMA networks (use getPhoneType() to determine if on a CDMA network).
例如或LocationManager.getLastKnownLocation()
。
String locale = context.getResources().getConfiguration().locale.getCountry();
依赖于设备的区域设置,该区域在全球范围内都是相同的,除非用户手动更改它。
有什么区别:
String locale = context.getResources().getConfiguration().locale.getCountry();
和
TelephonyManager tm = (TelephonyManager)this.getSystemService(this.TELEPHONY_SERVICE);
String countryCodeValue = tm.getNetworkCountryIso();
我需要的是这样的(很难测试)。用户来自美国,带着他的 sim 卡去法国旅行,并在国外使用他的 sim 卡,设备一直是英语(美国)。当他到达法国时,我需要从代码中获取法国。怎么做才对?
使用TelephonyManager.getNetworkCountryIso()
例如Returns the ISO country code equivalent of the current registered operator's MCC (Mobile Country Code).
Availability: Only when user is registered to a network. Result may be unreliable on CDMA networks (use getPhoneType() to determine if on a CDMA network).
或LocationManager.getLastKnownLocation()
。
String locale = context.getResources().getConfiguration().locale.getCountry();
依赖于设备的区域设置,该区域在全球范围内都是相同的,除非用户手动更改它。