3

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.

karllindmark
  • 6,031
  • 1
  • 26
  • 41
ARDaniyal
  • 159
  • 3
  • 10

2 Answers2

2

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.

Jon Hanna
  • 110,372
  • 10
  • 146
  • 251
  • Sory for confusion, actually I want international dialing code. Is there any method in android to get? – ARDaniyal Aug 09 '10 at 13:49
  • Sorry, ISO codes and dialing codes is the bit I know about in your question. However you could try building a listing from http://en.wikipedia.org/wiki/List_of_country_calling_codes whatever your language or platform. – Jon Hanna Aug 09 '10 at 13:58
0

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.

Ben Dowling
  • 17,187
  • 8
  • 87
  • 103