【发布时间】:2023-12-16 04:38:01
【问题描述】:
由于GDPR,我需要检查用户的位置 - 用户是否来自欧盟。到目前为止,我已经找到了这些解决方案 -
-
Get Country using the Phone's language configuration(如果用户使用英文美国版,即使他可能来自其他国家/地区,也会误导)。
String locale = context.getResources().getConfiguration().locale.getCountry(); -
Get Location using the GPS(需要粗略定位权限,我不想添加,特别是因为 Android 6.0+ 运行时权限)。
private void getCountryCode(final Location location) { Helper.log(TAG, "getCountryCode"); AsyncTask<Void, Void, String> countryCodeTask = new AsyncTask<Void, Void, String>() { final float latitude = (float) location.getLatitude(); final float longitude = (float) location.getLongitude(); // Helper.log(TAG, "latitude: " + latitude); List<Address> addresses = null; Geocoder gcd = new Geocoder(mContext); String code = null; @Override protected String doInBackground(Void... params) { try { addresses = gcd.getFromLocation(latitude, longitude, 1); code = addresses.get(0).getCountryCode(); } catch (IOException e) { e.printStackTrace(); } return code; } @Override protected void onPostExecute(String code) { Helper.log(TAG, "onPostExecute"); mCountryCodeListener.returnCountryCode(code); } }; if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.GINGERBREAD_MR1) { countryCodeTask.execute(); } else { countryCodeTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); } } -
Get Location using the SIM card or Wi-Fi(不能在没有 SIM 卡或 Wi-Fi 的桌子上使用,而我的应用可以在没有互联网连接或 Wi-Fi 的设备上使用)。
TelephonyManager tm = (TelephonyManager)this.getSystemService(Context.TELEPHONY_SERVICE); String countryCodeValue = tm.getNetworkCountryIso();
如果用户来自欧盟地区,是否可以找出用户的位置?
我不需要确切的位置,甚至国家都可以。
是否有另一种方法也可能需要位置权限(不是粗略的位置权限也会有帮助)?
请注意,这个问题不是任何其他问题的重复,因为我的情况没有被任何其他问题解决。
【问题讨论】:
-
你有什么解决办法吗?
-
@JithishPN 是的,您可以使用用户的 IP 地址来找出他来自哪个国家/地区。此外,如果您有兴趣仅查找用户是否来自欧盟,请检查正确标记的答案。对于 IP 地址,您可以查看 VicJordan 的以下答案。您可以尝试修剪 IP 地址的最后一部分以使其成为非个人(我认为这是可能的,但请重新检查)。问题中提到了其他方式。我知道从 IP 地址为您提供位置的服务是付费的,但您可以尝试搜索免费的服务或自己构建一个简单的服务。希望这会有所帮助。
标签: android geolocation location privacy android-gps