Android Nearby not working on Android Things

∥☆過路亽.° 提交于 2019-12-11 07:02:49

问题


I have have the following code:

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

If I run in on my phone it works as expected, but when I run it on my Android Things device I get the following error

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

From what I have noticed so far, my phone has Google Play Services version 12.8.72, but the Android Things image has Google Play Services 12.5.20

Anyone else had the same issue, and found a solution for it?


回答1:


Adding to Varun's answer, I'm going to guess that the default launcher is still running and hogging Connections. The IoT launcher will look something like this:

You can make your app the home app by adding an intent-filter to the manifest, like so (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>

Once you add the intent-filter to your manifest and install + run your app, you'll want to make sure the default launcher is no longer running. The easiest way to do this is to just reboot your Android Things device. Since your app is now the home app, it'll be the first app to launch after the reboot.

I'm not sure what Android Things version/system image you have, but you might also be able to do with one of the following adb commands:

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

or maybe:

adb shell am force-stop com.android.iotlauncher



回答2:


The version of Play Services is fixed to each release on Android Things, not updated automatically through the Play Store (see Google Services for more details on how Play Service works on Android Things). Because of this, you need to select a client library version for Nearby that will work with the 12.5.20 Play Services APK.

You may have success with a later version as well, but 12.0.1 is a known tested version of the Nearby client with Android Things 1.0.x:

dependencies {
    ...
    implementation "com.google.android.gms:play-services-nearby:12.0.1"
}



回答3:


Error code 8050 is API_CONNECTION_FAILED_ALREADY_IN_USE -- you can read more about that here.

Essentially, Nearby Connections doesn't (yet) support multiple clients using it, so there's some other app already using it that needs to be killed -- it's likely to be the app that sets up your Android Things device.



来源:https://stackoverflow.com/questions/51409543/android-nearby-not-working-on-android-things

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!