获取基于用户当前位置的Andr​​oid国家code

编程入门 行业动态 更新时间:2024-10-26 10:28:42
本文介绍了获取基于用户当前位置的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:

  • 我获取用户当前位置。
  • 使用此当前位置,我可以得到国家名获取用户的地址。
  • 但有什么办法,我可以得到从它的国名国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

    本文发布于:2023-06-07 21:54:37,感谢您对本站的认可!
    本文链接:https://www.elefans.com/category/jswz/34/568455.html
    版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
    本文标签:当前位置   国家   用户   Andr   oid

    发布评论

    评论列表 (有 0 条评论)
    草根站长

    >www.elefans.com

    编程频道|电子爱好者 - 技术资讯及电子产品介绍!