2

I'm trying to integrate Android Nearby (https://developers.google.com/nearby/) into my app, however when I try to use nearby.subscribe it fails with a "Missing microphone permission" error.

Since I could not find such a permission to add to AndroidManifest.xml, I searched for a bit and tried to add RECORD_AUDIO, but unfortunately it does not fix the problem.

Permissions asked (also at runtime):

<uses-permission android:name="android.permission.BLUETOOTH"/>
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN"/>
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE"/>
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<uses-permission android:name="android.permission.RECORD_AUDIO"/>

Code:

val nearby = Nearby.getMessagesClient(this, MessagesOptions.Builder().setPermissions(NearbyPermissions.BLE).build())
nearby.publish(Message("Hello".toByteArray()))
nearby.subscribe(object : MessageListener() {
   override fun onDistanceChanged(p0: Message?, p1: Distance?) {
      super.onDistanceChanged(p0, p1)
      toast("onDistanceChanged")
   }
   override fun onLost(p0: Message?) {
      super.onLost(p0)
      toast("onLost")
   }
   override fun onBleSignalChanged(p0: Message?, p1: BleSignal?) {
      super.onBleSignalChanged(p0, p1)
      toast("onBleSignalChanged")
   }

   override fun onFound(p0: Message?) {
      super.onFound(p0)
      toast("onFound")
   }
}).addOnFailureListener { toast("onFailure " + it.message) }
  .addOnSuccessListener { toast("onSuccess") }

Error:

2807: Missing microphone permission

How can I make the Nearby API work?

Matan Tsuberi
  • 461
  • 3
  • 11

1 Answers1

0

When creating the Nearby MessagesClient, you're specifying you'll use BLE permissions only. By default, the nearby connections api uses Strategy.DEFAULT which includes microphone access. Your subscription/publication will therefore fail from not having microphone permission.

To make Nearby API work, pass Subscribe Options and Publish Options that use the requested NearbyPermissions when subscribing or publishing respectively e.g. Strategy.BLE_ONLY for only NearbyPermissions.BLE.

Refer to the api explanation/documentation here. This is your error code and description.