无法获取用户使用我的 Android 应用程序所在的国家/地区
Not Able to Get Country Where User is Using My Android Application
我无法获得用户使用我的 Android 应用程序的确切国家/地区。
我尝试了很多方法,但没有得到确切的答案。
首先我像这样使用 TelephonyManager 但没有得到准确的答案
TelephonyManager tMgr = (TelephonyManager) CheckCountry.this
.getSystemService(Context.TELEPHONY_SERVICE);
phNo = tMgr.getLine1Number();
然后我使用了这个但是它的 return 值是通过从我的手机设置中获取的
String locale = getApplicationContext().getResources()
.getConfiguration().locale.getCountry();
谁有确切的解决方案,我可以通过它获得国家名称然后让我知道
如果连接到美国则 "US"
TelephonyManager tm = (TelephonyManager)this.getSystemService(this.TELEPHONY_SERVICE);
String countryCodeValue = tm.getNetworkCountryIso();
或
TelephonyManager tm = (TelephonyManager)this.getSystemService(this.TELEPHONY_SERVICE);
String countryCode = tm.getSimCountryIso();
好吧,我找到了更好的解决方案。通过使用 This api 我可以获得有关用户当前位置和国家/地区的所有详细信息。这是API
我无法获得用户使用我的 Android 应用程序的确切国家/地区。 我尝试了很多方法,但没有得到确切的答案。
首先我像这样使用 TelephonyManager 但没有得到准确的答案
TelephonyManager tMgr = (TelephonyManager) CheckCountry.this
.getSystemService(Context.TELEPHONY_SERVICE);
phNo = tMgr.getLine1Number();
然后我使用了这个但是它的 return 值是通过从我的手机设置中获取的
String locale = getApplicationContext().getResources()
.getConfiguration().locale.getCountry();
谁有确切的解决方案,我可以通过它获得国家名称然后让我知道
如果连接到美国则 "US"
TelephonyManager tm = (TelephonyManager)this.getSystemService(this.TELEPHONY_SERVICE);
String countryCodeValue = tm.getNetworkCountryIso();
或
TelephonyManager tm = (TelephonyManager)this.getSystemService(this.TELEPHONY_SERVICE);
String countryCode = tm.getSimCountryIso();
好吧,我找到了更好的解决方案。通过使用 This api 我可以获得有关用户当前位置和国家/地区的所有详细信息。这是API