获取国家TelephonyManager与locale.getCountry() [英] Get country TelephonyManager vs locale.getCountry()

查看:298
本文介绍了获取国家TelephonyManager与locale.getCountry()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

两者之间有什么区别?

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?

推荐答案

使用

返回与当前注册运营商的MCC(移动国家/地区代码)等效的ISO国家/地区代码.

Returns the ISO country code equivalent of the current registered operator's MCC (Mobile Country Code).

可用性:仅当用户注册到网络时.结果在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()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆