[英]Awareness API: com.google.android.gms.common.api.ApiException: 15
In my onCreate
I call the following function to detect the weather.在我的
onCreate
我调用以下函数来检测天气。
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.在我的 Gradle 文件中,我添加了以下依赖项。
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
.该应用程序可以正常启动并访问感知 API,但是它会在日志中引发以下错误:
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.我在文档和 Google/Stackoverflow 上都找不到对这个错误的解释。 Am I missing something obvious?
我错过了一些明显的东西吗?
For future readers, weather and place is now deprecated in the Google Awareness API.对于未来的读者,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).另一种选择是NumberEight SDK ,它可以做的比 Awareness 多得多(尽管在撰写本文时没有可用的区域划分)。
It performs a wide variety of context recognition tasks on both iOS and Android including:它在 iOS 和 Android 上执行各种上下文识别任务,包括:
It can also record user context for reports and analysis via the online portal.它还可以通过在线门户记录用户上下文以进行报告和分析。
To quickly receive weather updates in Java, you would write:要在 Java 中快速接收天气更新,您可以编写:
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.以下是一些iOS和Android示例项目。
Disclosure: I'm one of the developers.披露:我是开发人员之一。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.