是否有某种方法可以将侦听器注册到位置服务,以便当用户在设置应用程序中启用它们时会收到通知?
我面临的问题是,我向用户显示警报对话框以启用位置访问,通常流程就像,用户将点击[启用]正面响应,但是精英用户很多都不会经历这样的流程和通过转到设置直接手动启用位置访问。间接流的问题是,我无法忽略对话框。逻辑解决方案是监听位置访问启用事件的活动。有没有办法注册这样的听众?
另一种不那么简洁的方法是在回调中解除对话
@Override
public void onLocationChanged(Location location) {
// check if instantiated
if (enableLocationAccessAlert != null) {
enableLocationAccessAlert.dismissDialog();
}
findAddressPositionCamera(location);
}
答案 0 :(得分:1)
我认为当您实现LocationListener
时,已经通过这些函数支持它了:
@Override
public void onProviderDisabled(String provider) {
// Called when the provider is disabled by the user. If requestLocationUpdates is called on an already disabled provider, this method is called immediately.
}
@Override
public void onProviderEnabled(String provider) {
// Called when the provider is enabled by the user.
}
@Override
public void onStatusChanged(String provider, int status, Bundle extras) {
// Called when the provider status changes. This method is called when a provider is unable to fetch a location or if the provider has recently become available after a period of unavailability.
}
您只需使用这些来跟踪Location Service
状态。
希望这会有所帮助。