[英]How to determine an Android device's current country location regardless of user location settings?
I need to determine the country (iso3) the device is in even if the user's device has GPS turned off and does not allow apps to access it's location. 即使用户的设备已关闭GPS并且不允许应用访问其位置,我也需要确定设备所在的国家/地区(iso3)。
I also need to account for tablets that have no sim card and thus cannot use telephonyManager. 我还需要考虑没有SIM卡的平板电脑,因此不能使用telephonyManager。
For this reason I don't believe I can use the location manager (also because of these reasons: LocationManager requestLocationUpdates doesn't work ) 出于这个原因,我不相信我可以使用位置管理器(也是因为这些原因: LocationManager requestLocationUpdates不起作用 )
The approach I am thinking I will need is to make a simple HTTP request to a third party ip location api: eg http://www.ipinfodb.com/ip_location_api.php or https://freegeoip.net 我认为我需要的方法是向第三方ip位置api发出简单的HTTP请求:例如http://www.ipinfodb.com/ip_location_api.php或https://freegeoip.net
Is this the best way to do it? 这是最好的方法吗? What is the best open api to use?
什么是最好的开放api使用?
Your approach of third party ip location api seems right to currently. 你的第三方ip location api的方法目前似乎是正确的。 May be This would help you
可能这会对你有所帮助
http://ip-api.com/docs/api:json http://ip-api.com/docs/api:json
You can use the TelephonyManager 您可以使用TelephonyManager
TelephonyManager tm = (TelephonyManager)this.getSystemService(this.TELEPHONY_SERVICE);
String countryCode = tm.getNetworkCountryIso();
Update: Since you cannot use telephony I would suggest trying this, as it get's the users input from when they setup the device. 更新:由于您无法使用电话,我建议尝试这样做,因为它是用户在设置设备时输入的。
String locale = context.getResources().getConfiguration().locale.getCountry();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.