问题描述
两者之间有什么区别?
String locale = context.getResources().getConfiguration().locale.getCountry();
和
TelephonyManager tm = (TelephonyManager)this.getSystemService(this.TELEPHONY_SERVICE);
String countryCodeValue = tm.getNetworkCountryIso();
我需要的是这样的(很难测试).用户来自美国,带着SIM卡前往法国,并在国外使用SIM卡,该设备始终使用英语(US).我需要他到达法国时从代码中获得法国.怎么做对呢?
What I need is like this (hard to test it). The user is from US and travels to France with his sim card and uses his sim card abroad, the device is in English (US) all the time. I need when he arrives to France get France from code. How to do it right?
推荐答案
使用 TelephonyManager.getNetworkCountryIso()
可用性:仅当用户注册到网络时.结果在CDMA网络上可能不可靠(使用getPhoneType()确定是否在CDMA网络上).
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();
relies on the Locale of the device, which is going to be the same around the globe, unless user changes it manually.
这篇关于获取国家TelephonyManager与locale.getCountry()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!