Google Awareness API cannot register fence on emulator

730 Views Asked by At

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:

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

Has anyone any idea what might cause this problem?

3

There are 3 best solutions below

1
On

Have you tried setting the location in the emulator? This page has instructions:

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

0
On

To use the Awareness API, you need:

GooglePlayServices (on emulator, 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! At first glance, you can think that Awareness location API is an offline service. It's not. If you check your Google Developer Console, you can see the awareness requests to Google servers.

The error, kindly clarified by @jmols tell the tale: the API is trying access the security chain for connect with awareness service, and failing. 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.

0
On

According to the documentation, 7503 means:

ACL_ACCESS_DENIED: ACL authentication failed.

However, it seems like this is an emulator issue, because registering a TimeFence does work for me. Whereas Location- and ActivityFences don't.

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