Android Awareness API 多重围栏注册

标签 android google-play-services android-geofence google-awareness

我正在尝试在多个 session 中使用 Android 感知 API 注册多个位置围栏。但是每次我注册一个新的位置围栏时,它似乎会丢弃我的旧位置围栏并且不再触发它们。

String uniqueId = UUID.getid().toString() // sample to indicate this is always 
unique
AwarenessFence geoFence = LocationFence.in(lat, long, radius);
            Awareness.FenceApi.updateFences(
                        googleApiClient,
                        new FenceUpdateRequest.Builder()
                                .addFence(uniqueId, geoFence, pendingIntent)
                                .build())
                        .setResultCallback(new ResultCallback () { .....});

我的待定意向:

Intent intent = new Intent(GeoBroadcastReceiver.BROADCAST_KEY);
        Bundle bundle;
        bundle = new Bundle();
        bundle.putSerializable("model", model);
        intent.putExtra("specialBundle", bundle);
        PendingIntent geoBroadCastPendingIntent = PendingIntent.getBroadcast(context.getApplicationContext(), 0, intent, PendingIntent.FLAG_CANCEL_CURRENT);

The docs say this is how to add fences, but I wonder do i need to keep track of my old fences and anytime i use Awareness.FenceApi.updateFences, I need to add them in every-time?

最佳答案

我知道这是一个老问题,但我还是会回答,有人可能会觉得它有用。最近我遇到了类似的问题,我设法解决了。

在您的代码中,您将每个待定 Intent 设置为相同的 requestCode。因为那个和标志 FLAG_CANCEL_CURRENT 你覆盖了所有以前的未决 Intent (你总是设置为 0)。因此,要使其正常工作,您必须为每个笔划 Intent 设置唯一的 requestCode

关于Android Awareness API 多重围栏注册,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43702890/

相关文章:

python - 无法使用 NetMQ 在 Unity3d 和 Python 之间发送消息

android - SQLite Android无法打开数据库文件

android - 每个 Google Play 服务组件需要哪些权限?

java - 如何存储自定义对象的 ArrayList(地理围栏)

android - 在 Google 的地理围栏教程中看不到地理围栏过渡

android - 当背景颜色和文本颜色几乎相似时 OCR 不工作

c# - Tensorflowsharp 结果 getvalue() 很慢

android - gradle Android studio : "Cannot invoke method get() on null object" 错误

android - 在应用程序处于非 Activity 状态时处理 ActivityRecognition.API Intent

android - 地理围栏在 Android 中完全无法使用吗?