[英]Google Awareness API Places with com.google.android.gms.common.api.ApiException: 7508
[英]Awareness API: com.google.android.gms.common.api.ApiException: 15
在我的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);
}
});
}
在我的清單文件中,我添加了以下元數據和權限:
<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"/>
在我的 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:+'
該應用程序可以正常啟動並訪問感知 API,但是它會在日志中引發以下錯誤: com.google.android.gms.common.api.ApiException: 15
。 我在文檔和 Google/Stackoverflow 上都找不到對這個錯誤的解釋。 我錯過了一些明顯的東西嗎?
對於未來的讀者,Google Awareness API 現已棄用天氣和地點。
另一種選擇是NumberEight SDK ,它可以做的比 Awareness 多得多(盡管在撰寫本文時沒有可用的區域划分)。
它在 iOS 和 Android 上執行各種上下文識別任務,包括:
它還可以通過在線門戶記錄用戶上下文以進行報告和分析。
要在 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());
}
});
披露:我是開發人員之一。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.