Oreo 中的 OnLocationUpdatedListener 不起作用
OnLocationUpdatedListener in Oreo does not work
我有这个代码
LocationManager manager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
if (!manager.isProviderEnabled(LocationManager.GPS_PROVIDER)) {
UtilsDialog.displayPromptForEnablingGPS(MainActivity.this);
}
SmartLocation.with(getApplicationContext()).location()
.oneFix()
.start(new OnLocationUpdatedListener() {
@Override
public void onLocationUpdated(Location location) {
double Lat = location.getLatitude();
double Lng = location.getLongitude();
LatLng coordinate = new LatLng(Lat, Lng);
mMap.addMarker(new MarkerOptions().position(coordinate).title("you are here").icon(BitmapDescriptorFactory.fromResource(R.mipmap.ic_map_pin)));
CameraUpdate yourLocation = CameraUpdateFactory.newLatLng(coordinate);
mMap.animateCamera(yourLocation);
mMap.clear();
}
});
我已经在不同版本中检查过此代码,但在 Android 8 版本中不起作用,我使用了 SmartLocation 库
我该如何解决这个问题?
我通过在设备的开发人员选项中启用模拟位置应用程序解决了这个问题
这是模拟位置应用程序
我有这个代码
LocationManager manager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
if (!manager.isProviderEnabled(LocationManager.GPS_PROVIDER)) {
UtilsDialog.displayPromptForEnablingGPS(MainActivity.this);
}
SmartLocation.with(getApplicationContext()).location()
.oneFix()
.start(new OnLocationUpdatedListener() {
@Override
public void onLocationUpdated(Location location) {
double Lat = location.getLatitude();
double Lng = location.getLongitude();
LatLng coordinate = new LatLng(Lat, Lng);
mMap.addMarker(new MarkerOptions().position(coordinate).title("you are here").icon(BitmapDescriptorFactory.fromResource(R.mipmap.ic_map_pin)));
CameraUpdate yourLocation = CameraUpdateFactory.newLatLng(coordinate);
mMap.animateCamera(yourLocation);
mMap.clear();
}
});
我已经在不同版本中检查过此代码,但在 Android 8 版本中不起作用,我使用了 SmartLocation 库 我该如何解决这个问题?
我通过在设备的开发人员选项中启用模拟位置应用程序解决了这个问题
这是模拟位置应用程序