[英]How to determine an Android device's current country location regardless of user location settings?
即使用戶的設備已關閉GPS並且不允許應用訪問其位置,我也需要確定設備所在的國家/地區(iso3)。
我還需要考慮沒有SIM卡的平板電腦,因此不能使用telephonyManager。
出於這個原因,我不相信我可以使用位置管理器(也是因為這些原因: LocationManager requestLocationUpdates不起作用 )
我認為我需要的方法是向第三方ip位置api發出簡單的HTTP請求:例如http://www.ipinfodb.com/ip_location_api.php或https://freegeoip.net
這是最好的方法嗎? 什么是最好的開放api使用?
您可以使用TelephonyManager
TelephonyManager tm = (TelephonyManager)this.getSystemService(this.TELEPHONY_SERVICE);
String countryCode = tm.getNetworkCountryIso();
更新:由於您無法使用電話,我建議嘗試這樣做,因為它是用戶在設置設備時輸入的。
String locale = context.getResources().getConfiguration().locale.getCountry();
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.