Get country TelephonyManager vs locale.getCountry()

微笑、不失礼 提交于 2019-12-25 08:57:36

问题


what is the difference between:

String locale = context.getResources().getConfiguration().locale.getCountry(); 

and

TelephonyManager tm = (TelephonyManager)this.getSystemService(this.TELEPHONY_SERVICE);
String countryCodeValue = tm.getNetworkCountryIso();

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?


回答1:


Use 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).

Or LocationManager.getLastKnownLocation(), for example.

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.



来源:https://stackoverflow.com/questions/34578317/get-country-telephonymanager-vs-locale-getcountry

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!