相关疑难解决方法(0)

我在哪里? - 获得国家

Android移动实际上并一清二楚,它在哪里 - 但有通过类似的国家代码检索国家的一种方式?

无需了解确切的GPS位置 - 这个国家就足够了

我首先考虑使用时区,但实际上我需要更多的信息,因为如果位置是纽约或利马它会有所不同.

问题的背景:我有一个使用温度值的应用程序,我想将默认单位设置为Celsius或Fahrenheit,具体取决于位置是美国还是外部

android geolocation

122
推荐指数
10
解决办法
10万
查看次数

如何获得国家(或其ISO代码)?

获取国家/地区代码的最佳方式是什么?截至目前,我知道两种方法是通过TelephonyManager和另一种方法获取Locale,这是另一种在android中查找国家/地区代码的最佳和独特方式.

android location country-codes

49
推荐指数
6
解决办法
7万
查看次数

如何获得用户的国家/地区位置?

由于GDPR,我需要检查用户位置是否用户来自欧盟.直到现在我找到了这些解决方案 -

1)使用电话的语言配置获取国家(如果用户使用英语美国版本可能会误导,即使他可能来自其他国家/地区).

String locale = context.getResources().getConfiguration().locale.getCountry();
Run Code Online (Sandbox Code Playgroud)

2)使用GPS获取位置(需要位置Corse权限,我不想添加,特别是因为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 = …
Run Code Online (Sandbox Code Playgroud)

android location privacy geolocation android-gps

14
推荐指数
1
解决办法
3270
查看次数

Android 获取当前应用程序已从 Google Play 商店下载的国家/地区

我需要在下载我的应用程序时获取 PlayStore 设置的国家/地区(在应用程序中)。我只需要在从 Playstore 下载后安装我的应用程序时首次启动时获取此值。

如果没有,是否有办法从通过 AccountManager 检索到的帐户中获取国家/地区?

我已经四处搜寻,但尚未找到解决方案。非常感谢您的帮助!:)

sdk android accountmanager google-play

6
推荐指数
1
解决办法
4361
查看次数

意外的telephonyManager.getSimCountryIso()行为

我正在创建一个应用程序,该应用程序将根据您的移动网络提供商所在的国家/地区显示该国家/地区的所有替代移动网络提供商的列表。为此,我正在使用telephonyManager.getSimCountryIso()检索国家/地区代码。

官方的android开发人员文档说:“返回与SIM卡提供商的国家/地区代码等效的ISO国家/地区代码”,因此从此我希望国家/地区代码始终始终与设备位置无关。但这不是它实际的工作方式! 例如,我最近遇到这种情况:我有一个带有西班牙SIM卡的android设备,属于西班牙网络提供商。因此,如果我在西班牙,TelephonyManager.getSimCountryIso()将返回“ es”。一切正常。问题例如,当我去法国旅行时,我调试了应用程序,发现telephonyManager.getSimCountryIso()返回的国家代码为:“ nl”(来自荷兰! 。与西班牙使用的设备和SIM卡相同,因此国家/地区代码ISO仍应为“ es”。

我的问题是这种方法实际上如何工作?如果我使用西班牙SIM卡,为什么会收到国家代码“ nl”(荷兰)?

预先感谢您的任何帮助

android localization

6
推荐指数
1
解决办法
2568
查看次数

Android获取设备国家/地区代码

我想在不使用SIM卡的情况下获取设备国家/地区代码。

例如,如果国家/地区:斯里兰卡国家/地区代码:LK

我的最终目标是获取调用代码(斯里兰卡为+94)

我尝试过

TelephonyManager tm = (TelephonyManager)this.getSystemService(getApplicationContext().TELEPHONY_SERVICE);
String countryCodeValue = tm.getNetworkCountryIso();
Run Code Online (Sandbox Code Playgroud)

但这返回空字符串

android

6
推荐指数
1
解决办法
8066
查看次数

如何在android中获取国家代码(调用代码)?

如何在android代码中获取我的SIM的国家代码.我用过

TelephonyManager tm = (TelephonyManager)getSystemService(getApplicationContext().TELEPHONY_SERVICE);
          String countryCode = tm.getNetworkCountryIso();
Run Code Online (Sandbox Code Playgroud)

但在这里,我为孟加拉国获得了像"BD"这样的国家名称,我需要为孟加拉国提供+880.这段代码的工作原理与此类似. Locale.getDefault().getCountry();我需要代码为+ 91代表ind,+ 880代表bd.

java android

5
推荐指数
2
解决办法
1万
查看次数

Firebase Auth获取用户所在国家

我正在使用Firebase身份验证与谷歌登录和Facebook登录

有没有其他方法可以知道用户来自哪个国家/地区?

在应用程序知道用户来自哪个国家/地区之后,应用程序将决定向用户显示哪个服务/未来.

android firebase-authentication

4
推荐指数
1
解决办法
2652
查看次数

地址类getCountryCode()方法返回数字

public static Country getCountryFromLocation(Context cxt, List<Country> countryList, Location location, int maxAddress) {
    if (location == null || countryList == null || countryList.isEmpty()) {
        Log.d("ooo", "location == null || countryList == null || countryList.isEmpty()");
        return null;
    }

    double longitude = location.getLongitude();
    double latitude = location.getLatitude();

    Geocoder coder = new Geocoder(cxt);
    try {
        List<Address> addressList = coder.getFromLocation(latitude, longitude, maxAddress);

        for (Address address : addressList) {
            String curCountryCode = address.getCountryCode();

            Log.d("ooo", "address " + address.toString());
            if (TextUtils.isEmpty(curCountryCode)) {
                continue;
            }

            for (Country country …
Run Code Online (Sandbox Code Playgroud)

android google-maps country-codes geolocation mobile-country-code

3
推荐指数
1
解决办法
1403
查看次数