列出电话号码的所有国家/地区代码 [英] Listing all country codes of phone numbers

查看:897
本文介绍了列出电话号码的所有国家/地区代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想要一个电话号码的国家/地区代码列表。例如,United States(+1),United Kingdom(+44)......我知道libphonenumber是一个很好的工具,可以帮助解析电话,格式化和验证。但是,它似乎没有列出所有国家/地区代码的功能。但那些数据应该在libphonenumber的元数据中,对吗?有没有人有这方面的经验?

I'd like to have the country code list for phone numbers. Such as, United State (+1), United Kingdom (+44) ... I know that libphonenumber is a great tool to help phone parsing, formatting and validation. However, it doesn't seem to have the functionality for listing all country codes. But those data should be within the metadata in libphonenumber, right? Does anyone have experience on this?

推荐答案

我是一名Android开发人员。我正在使用libphonenumber库和java.util.Locale类来完成此操作,如下所示。这可能是迟到的反应,但希望它能帮助像我这样的人。

I am an android developer. I am using the libphonenumber library along with java.util.Locale class to complete this as follows. It may be late response, but hope it helps someone like me in future.

Set<String> set = PhoneNumberUtil.getInstance().getSupportedRegions();

String[] arr = set.toArray(new String[set.size()]);

for (int i = 0; i < arr.size(); i++) {
    Locale locale = new Locale("en", arr[i]);
    Log.d(TAG, "lib country:" + arr[i] + "  "+ locale.getDisplayCountry());
}

这篇关于列出电话号码的所有国家/地区代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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