0

我尝试使用以下代码更新围栏:

AwarenessFence locationFence = LocationFence.entering(latitude, longitude, radius);

    Awareness.FenceApi.updateFences(
            mGoogleApiClient,
            new FenceUpdateRequest.Builder()
                    .addFence(LOCATION_FENCE_KEY, locationFence, mPendingIntent)
                    .build())
            .setResultCallback(new ResultCallback<Status>() {
                @Override
                public void onResult(@NonNull Status status) {
                    if (status.isSuccess()) {
                        Log.i(TAG, "Fence was successfully registered.");
                    } else {
                        Log.e(TAG, "Fence could not be registered: " + status);
                    }
                }
            });

它在物理设备上运行良好,但在模拟器上我收到以下 logcat 消息:

Status{statusCode=unknown status code: 7503, resolution=null}

有谁知道什么可能导致这个问题?

4

3 回答 3

0

您是否尝试在模拟器中设置位置?此页面有说明:

https://developer.android.com/studio/run/emulator.html

于 2016-08-23T20:14:27.703 回答
0

要使用 Awareness API,您需要:

GooglePlayServices(在模拟器上,Google APIs)

到定位围栏:在设备上激活定位服务。如果在模拟器或支架设备上,我认为你可以伪造它。

似乎活动检测意识使用了一堆复杂的传感器,如加速度计、陀螺仪、位置等。所以我现在不知道在模拟器上的效率有多高。

最后,设备/模拟器需要互联网连接!乍一看,你可以认为 Awareness location API 是一个离线服务。不是。如果您检查您的 Google Developer Console,您可以看到对 Google 服务器的感知请求。

@jmols 澄清的错误说明了这个故事:API 正在尝试访问安全链以连接感知服务,但失败了。可能是因为设备没有网络连接。

如果您的模拟器上互联网连接,请在 Google 开发者控制台上仔细检查您的此 API 的凭据。

于 2016-11-10T19:36:30.493 回答
0

根据文档,7503 意味着

ACL_ACCESS_DENIED:ACL 认证失败。

但是,这似乎是一个模拟器问题,因为注册 aTimeFence对我有用。而 Location- 和 ActivityFences 没有。

AwarenessFence timeFence = TimeFence.inSaturdayInterval(TimeZone.getDefault(), 0, 24 * 60 * 60 * 1000);
于 2016-08-30T08:38:34.170 回答