简体   繁体   中英

Awareness API: com.google.android.gms.common.api.ApiException: 15

In my onCreate I call the following function to detect the weather.

private void detectWeather() {
        if( !checkLocationPermission() ) {
            return;
        }

        Awareness.getSnapshotClient(this).getWeather()
                .addOnSuccessListener(new OnSuccessListener<WeatherResponse>() {
                    @Override
                    public void onSuccess(WeatherResponse weatherResponse) {
                        Weather weather = weatherResponse.getWeather();
                    }
                })
                .addOnFailureListener(new OnFailureListener() {
                    @Override
                    public void onFailure(@NonNull Exception e) {
                        Log.e("Testing", "Could not get weather: " + e);
                    }
                });
    }

In my Manifest file I have added the following meta data and permissions:

<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="com.google.android.gms.permission.ACTIVITY_RECOGNITION" />

<meta-data
    android:name="com.google.android.awareness.API_KEY"
    android:value="MYKEY"/>

<meta-data
    android:name="com.google.android.geo.API_KEY"
    android:value="MYKEY"/>

And in my Gradle file I've added the following dependencies.

compile 'com.google.android.gms:play-services:+'
compile 'com.google.android.gms:play-services-gcm:+'
compile 'com.google.android.gms:play-services-location:+'
compile 'com.google.android.gms:play-services-awareness:+'

The app launches fine and gets to the awareness API, however it throws the following error in the log: com.google.android.gms.common.api.ApiException: 15 . I can't really find the explanation for this error in the documentation nor on Google/Stackoverflow. Am I missing something obvious?

For future readers, weather and place is now deprecated in the Google Awareness API.

An alternative is the NumberEight SDK , which can do a lot more than Awareness (although no regioning is available at the time of writing).

It performs a wide variety of context recognition tasks on both iOS and Android including:

  • Real-time physical activity detection
  • Current place categories
  • Motion detection
  • Reachability
  • Local weather

It can also record user context for reports and analysis via the online portal.

To quickly receive weather updates in Java, you would write:

NumberEight ne = new NumberEight();

ne.onWeatherUpdated(
    new NumberEight.SubscriptionCallback<NEWeather>() {
        @Override
        public void onUpdated(@NonNull Glimpse<NEWeather> glimpse) {
            Log.d("CurrentWeather", glimpse.getMostProbable().toString());
        }
    });

Here are some iOS and Android example projects.

Disclosure: I'm one of the developers.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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