android - 网络提供商位置始终返回 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 已启用
解决方案
推荐阅读
- cassandra - 用于快照管理的 cassandra 工具
- scala - Scala中“按名称调用”和Function0之间的区别
- autohotkey - 如何在 AutoHotkey 的 FileAppend 中转义逗号?
- c++ - 与多个用户一起处理 SEAL 密文
- java - 将bean xml转换为spring boot注解
- python-3.x - Python - 调用随机函数并创建一个线程
- sql-server - 当我向我的 jsquery 日历添加时间时,它正在更改为不同的时间
- entity-framework - Entity Framework Core 显示警告消息
- android - rxjava +改造-如何等待并获得android中第一个可观察的结果?
- php - PHP 和 MySQLi 错误 - 用户 'root'@'localhost' 的访问被拒绝(使用密码:否)