简体   繁体   English

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

[英]Google Awareness API cannot register fence on emulator

I try to update fence using following code: 我尝试使用以下代码更新篱笆:

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);
                    }
                }
            });

It works fine on physical device, but on emulator I get following logcat message: 它在物理设备上工作正常,但是在仿真器上,我收到以下logcat消息:

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

Has anyone any idea what might cause this problem? 有谁知道什么可能导致此问题?

Have you tried setting the location in the emulator? 您是否尝试过在模拟器中设置位置? This page has instructions: 此页面上有说明:

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

According to the documentation, 7503 means : 根据文档, 7503表示

ACL_ACCESS_DENIED: ACL authentication failed. ACL_ACCESS_DENIED:ACL身份验证失败。

However, it seems like this is an emulator issue, because registering a TimeFence does work for me. 但是,这似乎是模拟器问题,因为注册TimeFence确实对我TimeFence Whereas Location- and ActivityFences don't. 而位置围栏和活动围栏则没有。

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

To use the Awareness API, you need: 要使用Awareness API,您需要:

GooglePlayServices (on emulator, Google Apis) GooglePlayServices(在模拟器上为Google Apis)

To Location Fences: Location services activated on device. 到位置围栏:在设备上激活了位置服务。 If on emulator or stand device, I think you can fake it. 如果在模拟器或站立设备上,我认为您可以伪造它。

Seems that activity detect awareness uses a complex bunch of sensors like accelerometer, giroscope, locations, etc. So I don't now how efficient that can be on emulator. 似乎活动检测意识使用了一系列复杂的传感器,例如加速度计,陀螺仪,位置等。因此,我现在不了解模拟器的效率如何。

And, finally, the device/emulator needs Internet connection! 最后,设备/仿真器需要Internet连接! At first glance, you can think that Awareness location API is an offline service. 乍一看,您可以认为Awareness location API是一种离线服务。 It's not . 不是 If you check your Google Developer Console, you can see the awareness requests to Google servers. 如果您检查自己的Google Developer Console,则可以看到对Google服务器的感知请求。

The error, kindly clarified by @jmols tell the tale: the API is trying access the security chain for connect with awareness service, and failing. 错误由@jmols清楚地说明了:API正在尝试访问安全链以与感知服务建立连接,但失败了。 Probably because the device doesn't have network connection. 可能是因为该设备没有网络连接。

If you have internet connection on your emulator, double check your credentials for this API on Google Developer console. 如果您的仿真器具有互联网连接,请在Google Developer控制台上仔细检查此API的凭据。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM