在我的应用程序中,我有多个地理围栏,我希望它们具有唯一的待定意图,并具有不同的额外数据。但现在发生的是,对于我所有的地理围栏,正在触发的未决意图都是为最后一个地理围栏添加的,而不是分配给用户刚刚创建的特定地理围栏的。
例如,当我有2个地理围栏时,对于第一个,我会在挂起的意图中添加额外的字符串“AAA”,然后添加第二个带有额外“BBB”的地理围栏
然后输入第一个地理围栏,我将收到带有“BBB”的通知,而不是正确的“AAA”
我做错了什么?下面是我添加一个新地理围栏的代码:
public void addGeofencing(final MyObject myObject){
Geofence geofence = (new Geofence.Builder()
.setRequestId(myObject.getId())
.setCircularRegion(
myObject.getLat(),
myObject.getLon(),
RADIUS_IN_METERS
)
.setTransitionTypes(Geofence.GEOFENCE_TRANSITION_ENTER |
Geofence.GEOFENCE_TRANSITION_EXIT)
.setExpirationDuration(Geofence.NEVER_EXPIRE)
.build());
client.addGeofences(getGeofencingRequest(geofence),getGeofencePendingIntent(myObject.getExtraString))
.addOnSuccessListener(new OnSuccessListener<Void>() {
@Override
public void onSuccess(Void aVoid) {
System.out.println("GEOFENCE WORKED");
}
}).addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception e) {
System.out.println("GEOFENCE FAILED");
}
});
}
private GeofencingRequest getGeofencingRequest(Geofence geofence) {
GeofencingRequest.Builder builder = new GeofencingRequest.Builder();
builder.setInitialTrigger(GeofencingRequest.INITIAL_TRIGGER_ENTER);
builder.addGeofence(geofence);
return builder.build();
}
private PendingIntent getGeofencePendingIntent(String extraString) {
Intent intent = new Intent(context, GeofenceTransitionsIntentService.class);
intent.putExtra("extra",extraString);
return PendingIntent.getService(context, 0, intent, FLAG_UPDATE_CURRENT);
}