Android Nearby 不适用于 Android Things

标签 android android-things google-nearby

我有以下代码:

OnFailureListener onFailureListener = new OnFailureListener() {
  @Override
  public void onFailure(@NonNull Exception e) {
    Log.e(TAG, "bum", e);
  }
};
connectionsClient.startAdvertising("Device A", getPackageName(), myCallback, new AdvertisingOptions(STRATEGY))
        .addOnFailureListener(onFailureListener);

如果我在我的手机上运行它会按预期运行,但是当我在我的 Android Things 设备上运行它时我会收到以下错误

com.google.android.gms.common.api.ApiException: 17: Error resolution was canceled by the user, original error message: UNKNOWN_ERROR_CODE(8050): null 

据我目前所注意到的,我的手机有 12.8.72 版的 Google Play 服务,但 Android Things 图像有 12.5.20 版的 Google Play 服务

有没有人遇到同样的问题,并找到了解决方案?

最佳答案

添加到 Varun's answer ,我猜默认启动器仍在运行并占用连接。 IoT launcher看起来像这样:

enter image description here

您可以通过向 list 添加 intent-filter 使您的应用成为家庭应用,就像这样 ( official documentation ):

<application
android:label="@string/app_name">
<activity android:name=".HomeActivity">
    <!-- Launch activity as default from Android Studio -->
    <intent-filter>
        <action android:name="android.intent.action.MAIN"/>
        <category android:name="android.intent.category.LAUNCHER"/>
    </intent-filter>

    <!-- Launch activity automatically on boot, and re-launch if the app terminates. -->
    <intent-filter>
        <action android:name="android.intent.action.MAIN"/>
        <category android:name="android.intent.category.HOME"/>
        <category android:name="android.intent.category.DEFAULT"/>
    </intent-filter>
</activity>

将 intent-filter 添加到 list 并安装并运行您的应用后,您需要确保默认启动器不再运行。最简单的方法是重启您的 Android Things 设备。由于您的应用现在是家庭应用,它将是重启后第一个启动的应用。

我不确定您的 Android Things 版本/系统镜像是什么,但您也可以使用以下 adb 命令之一:

adb shell am force-stop com.android.iotlauncher.ota

或者也许:

adb shell am force-stop com.android.iotlauncher

关于Android Nearby 不适用于 Android Things,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51409543/

相关文章:

android - 使用 onSaveInstanceState 保存 TextView

android - :app:assembleRelease and assembleRelease之间的区别

javascript - 网络移动可靠高度

linux - adb 和 ifconfig 命令在带有 android things 的英特尔爱迪生中不起作用所以

android - 如何在启动时使用 root 权限在 Android Things 设备上运行 shell 脚本?

android - Boot设备时,如果无法连接到网络,如何在android things上设置当前时间?

android - 附近的 URL 通知出现在发现中,但没有通知图标

android - 如何强制 Google 附近使用 WiFi Direct?

android - 如何通过附近连接获取我自己的端点ID?

java - Android Studio 如何在不破坏自动提示的情况下将 java 类放入不同的文件夹?