I am building an Android app making communication between two devices. For this purpose, I am using Google Nearby Connection API and everything is working fine so far.
But specifically on Xiaomi 10X pro, the advertising cannot be established.
Following error is returned:
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)
The code used to advertise is not far from the Google documentation:
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)
}
}
}
I am digging the internet since but with no success. I cannot figure why Nearby Connection API would not be available for this specific device / model.
Has anybody already encountered such issue ?
As stated by @Xlythe, the device was bought on Chinese market and thus did not have Play Services installed at first.
After adding Play Store and Play Services, everthing works like a charm.