我正在构建一个在两个设备之间进行通信的 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 不适用于此特定设备/型号。
有没有人遇到过这样的问题?