获取国家代码
我可以使用 TelephonyManager::getNetworkCountryIso()
获取 ISO 形式的国家/地区代码,因为它返回 US 表示美国等,但如何获取数字国家/地区拨号代码?
我似乎找不到任何函数为我提供所需的数据,因为我需要一个函数(例如)为美国/加拿大返回 01
,92 巴基斯坦等。
I can get the country code in ISO-form using TelephonyManager::getNetworkCountryIso()
, as it returns US for USA and such, but how can I get the numeric country dialing code?
I can't seem to find any functions provides me with the data I'm looking for, as I need a function that (for example) returns 01
for USA/Canada, 92
for Pakistan and so on.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
由于它们是一个简短的列表,具有到字母代码的清晰映射,您是否可以只存储一个映射?
我不确定这是否是您想要的,因为巴基斯坦的 ISO 数字国家代码是 586,而您的问题引用了“92”,这是巴基斯坦的国际拨号代码。但同样的原理也可以发挥作用。
Since they're a short list, with a clear mapping to the alpha codes, could you perhaps just store a mapping?
I'm not sure this is what you want though, since the ISO numeric country code for Pakistan is 586 and your question quotes "92", which is the international dialing code for Pakistan. The same principle would work though.
您可以在 http://country.io/phone.json< 获取 ISO2 国家/地区代码到国际拨号代码的 JSON 映射/a>.下面是一个使用它的简单 PHP 示例:
请参阅 http://country.io/data/ 了解更多信息相关数据。
You can get a JSON mapping of ISO2 country code to international dialing code at http://country.io/phone.json. Here's a simple PHP example that makes use of it:
See http://country.io/data/ for more related data.