可靠的方法来获得用户是在国内? [英] Reliable method to get the country the user is in?

查看:147
本文介绍了可靠的方法来获得用户是在国内?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我通常会得到该国从设备的语言。它的工作原理,但现在我不得不承认巴西。和大多数的设备只有葡萄牙语(pt_PT),并没有葡萄牙语(巴西)选项。

I usually get the country from the device's language. It works but now I have to recognize Brazil. And most of the devices only have portuguese (pt_PT), and no portuguese (Brazil) option.

我查了一下这个线程:我在哪里? - 获得国家

I checked this thread: Where am I? - Get country

方法

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

 String locale = context.getResources().getConfiguration().locale.getDisplayCountry();

都还在语言而已,于事无补。

Are still language-only, doesn't help.

还有与SIM卡的建议,但我不知道这是否会可靠地工作(做所有的SIM卡有这种独特的身份?),也有点不正是我需要的,因为用户可以' T改变它(这是情况下,如果它是一个设置),它会排除使用设备用户无需SIM卡(也许他们只是使用WLAN)。

There's also the suggestion with the sim-card, but I'm not sure if this will work reliably (do all sim cards have this unique identification?), it's also a bit not exactly what I need because the user can't change it (which is the case if it was a setting), and it will exclude users using a device without sim-card (maybe they just use WLAN).

还有地理位置的建议,但在已停用它的设备这将可能无法正常工作。还是我错了?

There's also geolocation suggestion, but this will probably not work in devices which have deactivated it. Or am I wrong?

如果没有别的帮助我会让我的应用程序对话框或菜单设置,使用户可以选择它。不过,我想先确认是否有任何可靠的可能性与设备。

If nothing else helps I would make a dialog or menu setting in my app so the user can select it there. But I would first like to confirm if there's any reliable possibility with the device.

推荐答案

您可以拉的位置<一href="http://developer.android.com/reference/android/telephony/TelephonyManager.html#getNetworkCountryIso%28%29">from手机网络:

TelephonyManager.getNetworkCountryIso()

或<一href="http://developer.android.com/reference/android/telephony/TelephonyManager.html#getSimCountryIso%28%29">from SIM卡:

TelephonyManager.getSimCountryIso()

或者,如果have用户的电话号码,你可以将它通过这个数据

Or, if you have the user's phone number, you may be able to match it to the country through this data.

在理想情况下,你可以使用所有这三个(以某种顺序,也许是SIM卡,电话号码,然后网络),如果没有工作,使用反向地理定位作为最后的手段。

Ideally, you could use all three of these (in some order, perhaps SIM, Phone #, then Network), and if none works, use reverse geolocation as a last resort.

这篇关于可靠的方法来获得用户是在国内?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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