【发布时间】:2017-03-02 07:41:21
【问题描述】:
我必须在退出时更新
geoFence。为此,我需要当时的当前位置。
当我的应用关闭时我没有onLocationChanged 的监听器。并且为了
更新 geoFence 我需要我的位置。他们有什么方法可以在Geofence.GEOFENCE_TRANSITION_EXIT获得当前位置
public void broadcastUpdateGeoFences() {
MainActivity.isGeoFenceAdded = false;//It tells to update geoFence
Intent intent = new Intent(Constants.RECEIVER_GEOFENCE);
intent.putExtra("done", 1);
sendBroadcast(intent);
}
MainActivity 中的广播接收器
private BroadcastReceiver receiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
Bundle bundle = intent.getExtras();
if (bundle != null) {
int resultCode = bundle.getInt("done");
if (resultCode == 1) {
if(!MainActivity.isGeoFenceAdded){
updateGeoFencesOnCurrentExit();//I need current location here
}
}
}
}
};
一切正常。但是当应用关闭时,无法找到在退出时传递 currentLocation 的方法。
private void updateGeoFencesOnCurrentExit(Location currentLocation){
locationHandler.updateGeoFences(currentLocation);
}
【问题讨论】:
-
您是否为此使用 Intent 服务?
-
是的,我知道它应该是广播接收器
-
您的实际添加地理围栏请求在哪里?
标签: android locationlistener android-geofence