获取基于用户当前位置的Andr​​oid国家code [英] Get country code based on user's current location Android

查看:302
本文介绍了获取基于用户当前位置的Andr​​oid国家code的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经尝试了以下code获得国家code名称

I have already tried out the following code to get country code name

TelephonyManager tm = (TelephonyManager)getActivity().getSystemService(getActivity().TELEPHONY_SERVICE);
        String countryCodeValue = tm.getNetworkCountryIso();

但我想,如果我想获得当前的国家code中,用户是这不起作用。

But I guess this does not work if I want to get current country code in which the user is.

例如,如果用户旅行从一个国家到另一个国家我想获得该国code,他是在

For example if user travels from one country to another I want to get the country code in which he is in.

我有一个解决方案,使用户的当前国家code,但我坚持:

I have a solution to get user's current country code but I am stuck:


  1. 我获取用户当前位置。

  2. 使用此当前位置,我可以得到国家名获取用户的地址。

但有什么办法,我可以得到从它的国名国code在android系统?

But is there any way I can get the country code from its country name in android ?

也请让我知道我是否有更有效的方法。

Also please let me me know if there is more efficient way.

感谢:)

推荐答案

您可以通过 getResources()。getConfiguration获得ISO 3166-1α-2(美国,英国等),()。 locale.toString()。分裂(_)[1]

这篇关于获取基于用户当前位置的Andr​​oid国家code的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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