【问题标题】:Android Nearby Connection API not available for specific devicesAndroid Nearby Connection API 不适用于特定设备
【发布时间】:2021-06-10 21:11:51
【问题描述】:

我正在构建一个在两台设备之间进行通信的 Android 应用。 为此,我正在使用 Google Nearby Connection API,到目前为止一切正常。

但具体在小米10X pro上,无法建立广告。

返回以下错误:

 com.google.android.gms.common.api.ApiException: 17: API: Nearby.CONNECTIONS_API is not available on this device.
    at com.google.android.gms.common.api.internal.zad.zaa(Unknown Source:4)
    at com.google.android.gms.common.api.internal.zaf.zaa(Unknown Source:16)
    at com.google.android.gms.common.api.internal.GoogleApiManager$zaa.zac(Unknown Source:175)
    at com.google.android.gms.common.api.internal.GoogleApiManager$zaa.onConnectionFailed(Unknown Source:95)
    at com.google.android.gms.common.api.internal.GoogleApiManager$zaa.connect(Unknown Source:219)
    at com.google.android.gms.common.api.internal.GoogleApiManager$zaa.zaa(Unknown Source:112)
    at com.google.android.gms.common.api.internal.GoogleApiManager.handleMessage(Unknown Source:145)
    at android.os.Handler.dispatchMessage(Handler.java:103)
    at com.google.android.gms.internal.base.zap.dispatchMessage(Unknown Source:8)
    at android.os.Looper.loop(Looper.java:224)
    at android.os.HandlerThread.run(HandlerThread.java:67)

用来做广告的代码离谷歌文档不远:

private fun startAdvertising() {
    AdvertisingOptions.Builder()
      .setStrategy(Strategy.P2P_POINT_TO_POINT)
      .build()
      .also { options ->
        Nearby
          .getConnectionsClient(context)
          .startAdvertising(
            "card",
            "com.app.my",
            connectionLifecycleCallback,
            options
          )
          .addOnSuccessListener {
            FL.d("Advertising with success")
          }
          .addOnFailureListener { e: Exception? ->
            FL.e("Advertising failed", e)
          }
      }
  }

从那以后我一直在挖掘互联网,但没有成功。 我不明白为什么附近连接 API 不适用于此特定设备/型号。

有人遇到过这样的问题吗?

【问题讨论】:

  • 此设备是否有 Google Play 商店?附近是 Google Play 服务的一部分,在没有 Play 商店的设备上不可用。

标签: android google-nearby google-nearby-connections


【解决方案1】:

正如@Xlythe 所说,该设备是在中国市场上购买的,因此一开始没有安装 Play Services。

添加 Play 商店和 Play 服务后,一切都像魅力一样发挥作用。

【讨论】:

    猜你喜欢
    • 2021-10-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-02-19
    • 1970-01-01
    • 2021-12-21
    • 1970-01-01
    相关资源
    最近更新 更多