开发者

Get Country code

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.


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.


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:

$codes = json_decode(file_get_contents("http://country.io/phone.json"), true);
echo $codes['US'];
// => 1
echo $codes['PK'];
// => 92

See http://country.io/data/ for more related data.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜