android - 转换后删除触发的地理围栏

标签 android transition android-geofence

我试图在输入地理围栏后删除它,以阻止它重新触发输入转换。从一个类似的问题中,我得到了这条行之有效的行

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);

或者您可以从收到的 Intent 中获取地理围栏。

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);

关于android - 转换后删除触发的地理围栏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31678182/

相关文章:

android - 带有多个按钮的通知

android - 您如何在 Android 中请求 MANAGE_EXTERNAL_STORAGE 权限?

Android:mySQL,建表命令

javascript - jQuery fadein 效果转移到另一个页面

java - Android地理围栏广播接收器未触发

android - Android 地理围栏示例代码中的错误?任何人都可以确认吗?

android - 我可以使用 Xamarin.Forms 的 Xamarin.Android 试用版吗?

r - 是否有一个 R 包可以从频率表中计算一阶转换矩阵?

jquery - 如何在用户滚动到 N 点后触发动画 - 具有多个动画的 jQuery 路点 .animate()

java - 创建用户定义的地理围栏的算法