Google Awareness API无法在模拟器上注册fence

时间:2016-08-11 08:34:49

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

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

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}

有谁知道可能导致这个问题的原因是什么?

3 个答案:

答案 0 :(得分:0)

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

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

答案 1 :(得分:0)

根据文件,7503 means

  

ACL_ACCESS_DENIED:ACL身份验证失败。

但是,这似乎是一个模拟器问题,因为注册TimeFence对我有用。而位置和活动费用不是。

AwarenessFence timeFence = TimeFence.inSaturdayInterval(TimeZone.getDefault(), 0, 24 * 60 * 60 * 1000);

答案 2 :(得分:0)

要使用Awareness API,您需要:

GooglePlayServices(在模拟器上,Google Apis)

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

似乎活动检测意识使用了一系列复杂的传感器,如加速度计,giroscope,位置等。所以我现在还不具备仿真器的效率。

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

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

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