首页 > 解决方案 > 网络提供商位置始终返回 false(已禁用)

问题描述

所以我使用虚拟设备来测试一些代码,但即使启用了 wifi,网络提供商也会返回 false (onProviderDisabled)。

顺便说一句,当我使用 gps 提供程序时代码的工作原理

          Toast.makeText(this, "Guardando ubicacion...", Toast.LENGTH_SHORT).show();
            LocationManager locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
             LocationListener locationListener = new LocationListener() {
                @Override
                public void onLocationChanged(Location location) {
                        locationReal = location;
                        sharedPreferences.edit().putFloat("Latitude",(float) locationReal.getLatitude());
                        sharedPreferences.edit().putFloat("Longitude",(float)locationReal.getLongitude());
                        Toast.makeText(MainActivity.this, "Ubicacion guardada!", Toast.LENGTH_LONG).show();
                    Log.i("YES", "latitude" + locationReal.getLatitude() + "longitude" + locationReal.getLongitude());
                }

                @Override
                public void onStatusChanged(String provider, int status, Bundle extras) {

                }

                @Override
                public void onProviderEnabled(String provider) {
                    Log.i("YES", "onProviderEnabled: ");
                }

                @Override
                public void onProviderDisabled(String provider) {
                    Log.i("NO", "onProviderDisabled: ");
                }
            };
            locationManager.requestSingleUpdate(LocationManager.NETWORK_PROVIDER, locationListener, null);

位置侦听器应调用 onProviderEnabled 因为虚拟设备 wifi 已启用

标签: android

解决方案


推荐阅读