【问题标题】:Not Able to Get Country Where User is Using My Android Application无法获取用户使用我的 Android 应用程序的国家/地区
【发布时间】:2015-08-11 20:25:51
【问题描述】:

我无法获得用户使用我的 Android 应用程序的确切国家/地区。 我尝试了很多方法,但没有得到确切的答案。

首先我像这样使用 TelephonyManager 但没有得到准确的答案

TelephonyManager tMgr = (TelephonyManager) CheckCountry.this
                    .getSystemService(Context.TELEPHONY_SERVICE);
            phNo = tMgr.getLine1Number();

然后我使用了这个,但它通过从我的手机设置获取返回值

String locale = getApplicationContext().getResources()
                    .getConfiguration().locale.getCountry();

有任何确切的解决方案,我可以通过它获得国家名称,然后让我知道

【问题讨论】:

    标签: android android-activity android-studio telephonymanager


    【解决方案1】:

    如果连接到美国,则为“美国”

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

    TelephonyManager tm = (TelephonyManager)this.getSystemService(this.TELEPHONY_SERVICE);
     String countryCode = tm.getSimCountryIso();
    

    【讨论】:

    • 这些对我不起作用。我什么也得不到。我在平板电脑上使用我的应用程序。它不包含任何模拟插槽。
    • 您可以获取经纬度,然后使用谷歌地图服务确定位置。
    • 感谢@Learner。但我得到了更好的解决方案。你也可以试试这个。
    • 请检查您的链接是否损坏。我无法打开它
    【解决方案2】:

    好吧,我为此找到了更好的解决方案。通过使用此 api,我可以获得有关用户当前位置和国家/地区的所有详细信息。这是API

    API to Get Country

    【讨论】:

      猜你喜欢
      • 2014-01-12
      • 1970-01-01
      • 2012-08-06
      • 1970-01-01
      • 2023-03-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多