Android Things - 无法使用 Awareness API

标签 android google-play-services raspberry-pi3 android-things google-awareness

我在手机上使用较低版本 (9.4.0) 的相同代码,但出于某种原因它不能在 RPi3 上运行?我的构建.gradle

compile 'com.google.android.gms:play-services:10.0.0'
provided 'com.google.android.things:androidthings:0.4-devpreview'

list 权限

<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.INTERNET" />

方法

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());
                    }
                });
    }
}

日志

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

出于某种原因,它在告诉我已授予权限后停止。尽管该应用程序没有崩溃,但我有一个调用 getWeather() 的 OnClickListener,因此我可以重复单击但永远不会获取任何快照数据。我使用的是与手机相同的 API key ...

根据 docs 的说法,AndroidThings 支持 Awareness API,而且我看到有人声称使用列表中的 Nearby 和其他 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: 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

最佳答案

总的来说,Android Things 需要 11.0.0 的最低 Play Services 客户端版本。这是引入了 Play Services 的 IoT 变体的版本。 Support for Google Services 下的文档中对此进行了说明.

为获得最佳结果,您应该将库版本与与您正在运行的预览版 bundle 在一起的确切版本相匹配。您可以在 Release Notes 上找到这些版本号.

关于Android Things - 无法使用 Awareness API,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45703282/

相关文章:

android - 从 EditText 及其内容创建位图图像

android - 如何使用 Google Play 创建每周排行榜?

linux - 树莓派处于重启循环中

java - java.library.path 中没有 dhtreader

python - 当 Mysql 数据库服务器中触发触发器时,我可以在树莓派上运行 python 脚本吗?

android - Cassandra DB For Android,它的 API 以及如何使用它?

c# - UDP 广播不适用于 Android 手机热点 C#

android - 如何在 Android Studio 的模拟器上更新 Google Play 服务

iphone - 有什么可以在原生移动应用程序中实现而在 HTML5 网络应用程序中无法实现的?

android - Lollipop 上 Genymotion 中的 Google Play 服务(Android 5.0)