我希望向我的应用程序添加功能,允许我使用触发的Geofence的ID从数组中选择相应的示例(Url),然后将其传递给外部播放器进行流处理。
目前,我遵循geofencing,它使用挂起的意图连接到intentservice来管理geofence、转换等。
查看在主活动中设置的挂起的意图,我可以请求它在转换时返回geofence ID吗?我对android和这个api都很陌生,所以任何和所有的帮助都是非常感谢的!非常感谢!
发布于 2015-07-25 16:17:09
如果我正确理解您的问题(我可能不理解),则在发生转换事件时,应该已经返回Geofence ID。
当您的PendingIntent被触发时,解释文档:
您可以调用
GeofencingEvent.fromIntent(Intent)来获取转换类型、触发此意图的地理位置以及触发geofence转换的位置。
从结果的GeofencingEvent对象中,您可以调用getTriggeringGeofences()来检索导致转换的Geofence的列表,然后在每个Geofence上调用getRequestId()来检索ID。
编辑一些代码..。这是未经测试的(因为我拒绝跳关于测试Geofence边界的舞蹈!),但我希望它能起作用。我假设您已经有了一个工作Geofence设置,并且它正确地调用了您的IntentService。在IntentService中,您应该有一个onHandleIntent方法:
void onHandleIntent(Intent intent) {
// retrieve the GeofencingEvent from the passed Intent
GeofencingEvent ge = GeofencingEvent.fromIntent(intent);
// get the Geofences that triggered it
List<Geofence> fences = ge.getTriggeringGeofences();
// checking there is only one fence (bad assumption!!!!), retrieve the request Id
if (fences == null || fences.size() != 1) {
return;
}
String fenceID = fences.get(0).getRequestId();
// do something funky with it...
}您应该调试或记录每一行,以检查它是否正常工作。如果这不起作用或者不是你所期望的,请告诉我。
https://stackoverflow.com/questions/31625954
复制相似问题