Android的东西 - 不能使用Awareness API [英] Android Things - can't use Awareness API
问题描述
我在手机上使用较低版本(9.4.0)的相同代码,但出于某种原因,它不适用于RPi3?我的build.gradle
compile'com.google.android.gms:play-services:10.0.0'
提供'com.google.android.things:androidthings:0.4-devpreview'
清单权限
< uses-permission android:name =android.permission.ACCESS_FINE_LOCATION/>
< uses-permission android:name =android.permission.INTERNET/>
该方法
private void getWeather(){
//首先检查权限
if(ContextCompat.checkSelfPermission(this,Manifest.permission.ACCESS_FINE_LOCATION)
!= PackageManager .PERMISSION_GRANTED){
Log.e(标记,尚未授予的精细位置权限);
ActivityCompat.requestPermissions(this,new String [] {Manifest.permission.ACCESS_FINE_LOCATION},MY_PERMISSIONS_REQUEST_ACCESS_FINE_LOCATION);
} else {
System.out.println(else of getWeather());
Log.i(TAG,已授予精细位置权限);
// Weather
Awareness.SnapshotApi.getWeather(mGoogleApiClient).setResultCallback(new ResultCallback< WeatherResult>(){
@Override
public void onResult(@NonNull WeatherResult weatherResult){
if(!weatherResult.getStatus()。isSuccess()){
Log.e(TAG,Could not detect weather info);
mWeatherTextView.setText(无法检测天气信息);
mWeatherTextView.setTextColor(Color.RED);
System.out.println(NO WEATHER INFO);
return;
}
System.out.println(WEATHER INFO REC'D);
Weather weather = weatherResult.getWeather();
mWeatherTextView.setText(weather.toString());
}
});
logcat
08-15 23:46:09.504 411-432 /? I / WindowManager:销毁com.android.server.wm.WindowStateAnimator.destroySurface调用的表面(name = Starting com.example.cartier.thingsaware):2014 com.android.server.wm.WindowStateAnimator.destroySurfaceLocked:881 com.android .server.wm.WindowState.destroyOrSaveSurface:2073 com.android.server.wm.AppWindowToken.destroySurfaces:363 com.android.server.wm.WindowStateAnimator.finishExit:565 com.android.server.wm.WindowStateAnimator.stepAnimationLocked:491 com .android.server.wm.WindowAnimator.updateWindowsLocked:303 com.android.server.wm.WindowAnimator.animateLocked:704
08-15 23:46:09.594 411-1124 /? I / WindowManager:销毁com.android.server.wm.WindowStateAnimator.destroySurface调用的表面(name = com.android.iotlauncher / com.android.iotlauncher.IoTLauncher):2014 com.android.server.wm.WindowStateAnimator.destroySurfaceLocked :881 com.android.server.wm.WindowState.destroyOrSaveSurface:2073 com.android.server.wm.AppWindowToken.destroySurfaces:363 com.android.server.wm.AppWindowToken.notifyAppStopped:389 com.android.server.wm.WindowManagerService .notifyAppStopped:4456 com.android.server.am.ActivityStack.activityStoppedLocked:1252 com.android.server.am.ActivityManagerService.activityStopped:6902
08-15 23:46:11.780 411-479 /? E / TaskPersister:访问最近目录的文件错误(目录不存在?)。
08-15 23:46:35.798 3687-3687 /? I / System.out:其他getWeather()
08-15 23:46:35.798 3687-3687 /? I / MainActivity:罚款位置权限已被授予
由于某种原因, 。该应用程序不会崩溃,我有一个OnClickListener调用getWeather(),所以我可以重复点击,但从来没有得到任何快照数据。我使用了与手机相同的API密钥...
根据 docs Awareness API在AndroidThings&我见过项目是人们声称使用了附近和列表中的其他API。有人在AndroidThings上的Awareness API上获得成功吗?
在更新服务11.0.0后,应用程序立即关闭& logcat现在显示
08-17 18:13:28.510 3148-3148 /? I / System.out:onCreate
08-17 18:13:28.615 410-432 /? I / ActivityManager:显示com.example.cartier.thingsaware / .MainActivity:+ 1s45ms
08-17 18:13:28.665 410-525 /? I / WindowManager:销毁com.android.server.wm.WindowStateAnimator.destroySurface调用的表面(name = com.android.iotlauncher / com.android.iotlauncher.IoTLauncher):2014 com.android.server.wm.WindowStateAnimator.destroySurfaceLocked :881 com.android.server.wm.WindowState.destroyOrSaveSurface:2073 com.android.server.wm.AppWindowToken.destroySurfaces:363 com.android.server.wm.AppWindowToken.notifyAppStopped:389 com.android.server.wm.WindowManagerService .notifyAppStopped:4456 com.android.server.am.ActivityStack.activityStoppedLocked:1252 com.android.server.am.ActivityManagerService.activityStopped:6902
08-17 18:13:28.881 410-432 /? I / WindowManager:销毁com.android.server.wm.WindowStateAnimator.destroySurface调用的表面(name = Starting com.example.cartier.thingsaware):2014 com.android.server.wm.WindowStateAnimator.destroySurfaceLocked:881 com.android .server.wm.WindowState.destroyOrSaveSurface:2073 com.android.server.wm.AppWindowToken.destroySurfaces:363 com.android.server.wm.WindowStateAnimator.finishExit:565 com.android.server.wm.WindowStateAnimator.stepAnimationLocked:491 com .android.server.wm.WindowAnimator.updateWindowsLocked:303 com.android.server.wm.WindowAnimator.animateLocked:704
08-17 18:13:28.990 3148-3148 /?我/过程:发送信号。 PID:3148 SIG:9
08-17 18:13:29.047 410-929 /? I / ActivityManager:进程com.example.cartier.thingsaware(pid 3148)已经去世
08-17 18:13:29.047 410-525 /? I / WindowManager:WIN DEATH:窗口{9cbd0a u0 com.example.cartier.thingsaware / com.example.cartier.thingsaware.MainActivity}
08-17 18:13:29.048 410-525 /? I / WindowManager:销毁由com.android.server.wm.WindowStateAnimator.destroySurface调用的表面(名称= com.example.cartier.thingsaware / com.example.cartier.thingsaware.MainActivity):2014 com.android.server.wm .WindowStateAnimator.destroySurfaceLocked:881 com.android.server.wm.WindowState.removeLocked:1449 com.android.server.wm.WindowManagerService.removeWindowInnerLocked:2478 com.android.server.wm.WindowManagerService.removeWindowLocked:2436 com.android.server .wm.WindowState $ DeathRecipient.binderDied:1780 android.os.BinderProxy.sendDeathNotice:688<调用堆栈底部>
08-17 18:13:29.083 638-638 /? I / AndroidThingsLauncher:外设I / O端口
08-17 18:13:29.083 638-638 /? I / AndroidThingsLauncher:GPIO
最小播放服务客户端版本 11.0.0
。这是推出Play服务的物联网变体的版本。这在支持Google服务的文档中有详细说明。
为了获得最佳效果,您应该将库版本与您正在运行的预览版捆绑的确切版本进行匹配。您可以在发行说明上找到这些版本号。
I have the same code with a lower version (9.4.0) working on the phone but for some reason it won't work on RPi3? My build.gradle
compile 'com.google.android.gms:play-services:10.0.0'
provided 'com.google.android.things:androidthings:0.4-devpreview'
The manifest permissions
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.INTERNET" />
The method
private void getWeather() {
// Check for permission first
if (ContextCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION)
!= PackageManager.PERMISSION_GRANTED) {
Log.e(TAG, "Fine Location Permission not yet granted");
ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.ACCESS_FINE_LOCATION}, MY_PERMISSIONS_REQUEST_ACCESS_FINE_LOCATION);
} else {
System.out.println("else of getWeather()");
Log.i(TAG, "Fine Location permission already granted");
// Weather
Awareness.SnapshotApi.getWeather(mGoogleApiClient).setResultCallback(new ResultCallback<WeatherResult>() {
@Override
public void onResult(@NonNull WeatherResult weatherResult) {
if (!weatherResult.getStatus().isSuccess()) {
Log.e(TAG, "Could not detect weather info");
mWeatherTextView.setText("Could not detect weather info");
mWeatherTextView.setTextColor(Color.RED);
System.out.println("NO WEATHER INFO");
return;
}
System.out.println("WEATHER INFO REC'D");
Weather weather = weatherResult.getWeather();
mWeatherTextView.setText(weather.toString());
}
});
}
}
The logcat
08-15 23:46:09.504 411-432/? I/WindowManager: Destroying surface Surface(name=Starting com.example.cartier.thingsaware) called by com.android.server.wm.WindowStateAnimator.destroySurface:2014 com.android.server.wm.WindowStateAnimator.destroySurfaceLocked:881 com.android.server.wm.WindowState.destroyOrSaveSurface:2073 com.android.server.wm.AppWindowToken.destroySurfaces:363 com.android.server.wm.WindowStateAnimator.finishExit:565 com.android.server.wm.WindowStateAnimator.stepAnimationLocked:491 com.android.server.wm.WindowAnimator.updateWindowsLocked:303 com.android.server.wm.WindowAnimator.animateLocked:704
08-15 23:46:09.594 411-1124/? I/WindowManager: Destroying surface Surface(name=com.android.iotlauncher/com.android.iotlauncher.IoTLauncher) called by com.android.server.wm.WindowStateAnimator.destroySurface:2014 com.android.server.wm.WindowStateAnimator.destroySurfaceLocked:881 com.android.server.wm.WindowState.destroyOrSaveSurface:2073 com.android.server.wm.AppWindowToken.destroySurfaces:363 com.android.server.wm.AppWindowToken.notifyAppStopped:389 com.android.server.wm.WindowManagerService.notifyAppStopped:4456 com.android.server.am.ActivityStack.activityStoppedLocked:1252 com.android.server.am.ActivityManagerService.activityStopped:6902
08-15 23:46:11.780 411-479/? E/TaskPersister: File error accessing recents directory (directory doesn't exist?).
08-15 23:46:35.798 3687-3687/? I/System.out: else of getWeather()
08-15 23:46:35.798 3687-3687/? I/MainActivity: Fine Location permission already granted
For some reason it stops after telling me the permission is granted. The app doesn't crash though, I have an OnClickListener that calls getWeather() so I can repeatedly click but never get any snapshot data. I'm using the same API key that works on the phone...
According to the docs the Awareness API is supported on the AndroidThings & I've seen projects were people claim to have used Nearby & other APIs in the list. Has anyone had success with the Awareness API on AndroidThings?
After updating to play services 11.0.0 the app opens the immediately closes & the logcat now shows
08-17 18:13:28.510 3148-3148/? I/System.out: onCreate
08-17 18:13:28.615 410-432/? I/ActivityManager: Displayed com.example.cartier.thingsaware/.MainActivity: +1s45ms
08-17 18:13:28.665 410-525/? I/WindowManager: Destroying surface Surface(name=com.android.iotlauncher/com.android.iotlauncher.IoTLauncher) called by com.android.server.wm.WindowStateAnimator.destroySurface:2014 com.android.server.wm.WindowStateAnimator.destroySurfaceLocked:881 com.android.server.wm.WindowState.destroyOrSaveSurface:2073 com.android.server.wm.AppWindowToken.destroySurfaces:363 com.android.server.wm.AppWindowToken.notifyAppStopped:389 com.android.server.wm.WindowManagerService.notifyAppStopped:4456 com.android.server.am.ActivityStack.activityStoppedLocked:1252 com.android.server.am.ActivityManagerService.activityStopped:6902
08-17 18:13:28.881 410-432/? I/WindowManager: Destroying surface Surface(name=Starting com.example.cartier.thingsaware) called by com.android.server.wm.WindowStateAnimator.destroySurface:2014 com.android.server.wm.WindowStateAnimator.destroySurfaceLocked:881 com.android.server.wm.WindowState.destroyOrSaveSurface:2073 com.android.server.wm.AppWindowToken.destroySurfaces:363 com.android.server.wm.WindowStateAnimator.finishExit:565 com.android.server.wm.WindowStateAnimator.stepAnimationLocked:491 com.android.server.wm.WindowAnimator.updateWindowsLocked:303 com.android.server.wm.WindowAnimator.animateLocked:704
08-17 18:13:28.990 3148-3148/? I/Process: Sending signal. PID: 3148 SIG: 9
08-17 18:13:29.047 410-929/? I/ActivityManager: Process com.example.cartier.thingsaware (pid 3148) has died
08-17 18:13:29.047 410-525/? I/WindowManager: WIN DEATH: Window{9cbd0a u0 com.example.cartier.thingsaware/com.example.cartier.thingsaware.MainActivity}
08-17 18:13:29.048 410-525/? I/WindowManager: Destroying surface Surface(name=com.example.cartier.thingsaware/com.example.cartier.thingsaware.MainActivity) called by com.android.server.wm.WindowStateAnimator.destroySurface:2014 com.android.server.wm.WindowStateAnimator.destroySurfaceLocked:881 com.android.server.wm.WindowState.removeLocked:1449 com.android.server.wm.WindowManagerService.removeWindowInnerLocked:2478 com.android.server.wm.WindowManagerService.removeWindowLocked:2436 com.android.server.wm.WindowState$DeathRecipient.binderDied:1780 android.os.BinderProxy.sendDeathNotice:688 <bottom of call stack>
08-17 18:13:29.083 638-638/? I/AndroidThingsLauncher: Peripheral I/O ports
08-17 18:13:29.083 638-638/? I/AndroidThingsLauncher: GPIO
Overall, Android Things requires a minimum Play Services client version of 11.0.0
. This is the version where the IoT variant of Play Services was introduced. This is noted in the documentation under Support for Google Services.
For best results, you should match the library version to the exact version bundled with the preview release you are running. You can find those version numbers on the Release Notes.
这篇关于Android的东西 - 不能使用Awareness API的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!