【问题标题】:Android Things - can't use Awareness APIAndroid Things - 无法使用 Awareness API
【发布时间】:2023-03-29 04:24:01
【问题描述】:

我在手机上使用较低版本 (9.4.0) 的相同代码,但由于某种原因它无法在 RPi3 上运行?我的 build.gradle

compile 'com.google.android.gms:play-services:10.0.0'
provided '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() {

    // 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 密钥...

根据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

【问题讨论】:

  • 你试过最新版的AndroidThings吗? 0.5.0 与播放服务 11 developer.android.com/things/preview/releases.html
  • 谢谢@Blundell。尝试多次刷新 0.5.0 但没有运气。按照 ThingsConsole 的指示:创建产品(确定我有正确的 SOM 和左 32MB OEM 默认值)> 配置产品 > 构建设备映像(带有空包)> 下载和闪存但每次屏幕都是空白的。您为创建 RPi3 构建做了什么特别的事情吗?

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


【解决方案1】:

总体而言,Android Things 需要的最低 Play Services 客户端版本为 11.0.0。这是引入 Play Services 的 IoT 变体的版本。这在Support for Google Services 下的文档中有说明。

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

【讨论】:

  • 感谢@Devunwired 的反馈。现在使用 Play Services 11.0.0 应用程序打开并立即关闭显示启动器页面?请参阅上面的新 logcat。我拥有的东西版本(0.4.1)不是从控制台下载的,而是像所有以前的版本一样直接从网页下载。按照 Blundell 的建议,刷了 0.5.0 版(三次),但总是启动到空白屏幕?每次使用一个空包 & 可以 adb in 查看包列表但没有视频输出所以回到 0.4.1?关于如何进行的任何想法?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2023-03-13
相关资源
最近更新 更多