Android 转换后移除触发的土工栅栏

Android 转换后移除触发的土工栅栏,android,transition,android-geofence,Android,Transition,Android Geofence,我正在尝试在地理围栏被输入后移除它,以阻止它重新触发输入转换。从一个类似的问题中,我得到了这句话,效果很好 LocationServices.GeofencingApi.removeGeofences(mGoogleApiClient,getGeofencePendingIntent()).setResultCallback(this); 但是,它会删除所有地理围栏,而不仅仅是已触发的地理围栏 要选择要删除的正确ID,我需要做什么?您需要传递用于构建地理围栏的相同字符串 String geof

我正在尝试在地理围栏被输入后移除它,以阻止它重新触发输入转换。从一个类似的问题中,我得到了这句话,效果很好

LocationServices.GeofencingApi.removeGeofences(mGoogleApiClient,getGeofencePendingIntent()).setResultCallback(this);
但是,它会删除所有地理围栏,而不仅仅是已触发的地理围栏


要选择要删除的正确ID,我需要做什么?

您需要传递用于构建地理围栏的相同字符串

String geofenceId = "randomId";
Geofence geofence = new Geofence.Builder()
    .setRequestId(geofenceId)
    ....
    .build();

GeofencingRequest request = new GeofencingRequest.Builder()
    .addGeofence(geofence)
    ....
    .build();

LocationServices.GeofencingApi.addGeofences(mGoogleApiClient, request, pendingIntent);
要移除土工围栏,可以使用

List<String> geofencesToRemove = new ArrayList<>();
geofencesToRemove.add(geofenceId);
LocationServices.GeofencingApi.removeGeofences(mGoogleApiClient, geofencesToRemove);
List geofinesstoremove=new ArrayList();
geofencesToRemove.add(geofenceId);
位置服务。GeofencingApi。拆除围栏(MGoogleapClient、GeofencingApi StoreMove);
或者你可以从你收到的意向中得到地理围栏

GeofencingEvent event = GeofencingEvent.fromIntent( intent_you_got_from_geofence );
List<Geofence> triggeredGeofences = event.getTriggeringGeofences();
List<String> toRemove = new ArrayList<>();
for (Geofence geofence : triggeredGeofences) {
    toRemove.add(geofence.getRequestId());
}
LocationServices.GeofencingApi.removeGeofences(mGoogleApiClient, toRemove);
GeofencingEvent事件=GeofencingEvent.fromIntent(intent\u您从geofence获得的\u);
List triggeredGeofences=event.getTriggeringGeofines();
List toRemove=new ArrayList();
用于(土工栅栏土工栅栏:触发距离){
toRemove.add(geopfence.getRequestId());
}
位置服务。GeofencingApi。拆除围栏(mGoogleApiClient,toRemove);

您需要传递用于构建地理围栏的相同字符串

String geofenceId = "randomId";
Geofence geofence = new Geofence.Builder()
    .setRequestId(geofenceId)
    ....
    .build();

GeofencingRequest request = new GeofencingRequest.Builder()
    .addGeofence(geofence)
    ....
    .build();

LocationServices.GeofencingApi.addGeofences(mGoogleApiClient, request, pendingIntent);
要移除土工围栏,可以使用

List<String> geofencesToRemove = new ArrayList<>();
geofencesToRemove.add(geofenceId);
LocationServices.GeofencingApi.removeGeofences(mGoogleApiClient, geofencesToRemove);
List geofinesstoremove=new ArrayList();
geofencesToRemove.add(geofenceId);
位置服务。GeofencingApi。拆除围栏(MGoogleapClient、GeofencingApi StoreMove);
或者你可以从你收到的意向中得到地理围栏

GeofencingEvent event = GeofencingEvent.fromIntent( intent_you_got_from_geofence );
List<Geofence> triggeredGeofences = event.getTriggeringGeofences();
List<String> toRemove = new ArrayList<>();
for (Geofence geofence : triggeredGeofences) {
    toRemove.add(geofence.getRequestId());
}
LocationServices.GeofencingApi.removeGeofences(mGoogleApiClient, toRemove);
GeofencingEvent事件=GeofencingEvent.fromIntent(intent\u您从geofence获得的\u);
List triggeredGeofences=event.getTriggeringGeofines();
List toRemove=new ArrayList();
用于(土工栅栏土工栅栏:触发距离){
toRemove.add(geopfence.getRequestId());
}
位置服务。GeofencingApi。拆除围栏(mGoogleApiClient,toRemove);

谢谢,这真的很有帮助!很抱歉回复晚了,我已经离开这个国家几天了!非常有用的回答。谢谢你这真的很有帮助!很抱歉回复晚了,我已经离开这个国家几天了!非常有用的回答。谢谢