I want to use Google's Nearby Messages API to publish a simple message and I want to only use BLE for it so that no Nearby Permissions dialog is required. I am creating my MessagesClient
with just the NearbyPermissions.BLE
flag:
private MessagesClient messagesClient(Context context) {
return Nearby.getMessagesClient(context, messageOptions());
}
private MessagesOptions messageOptions() {
return new MessagesOptions.Builder()
.setPermissions(BLE)
.build();
}
public void publish(Context context) {
mMessagesClient = messagesClient(context);
mMessagesClient
.publish(mMessage) // publish without any PublishOptions
.addOnSuccessListener( // ... )
}
I am purposedly not setting any PublishOptions
object because the documentation specifically states that the Strategy.BLE
should only be used for subscriptions since it has an infinite TTL. However, messages are failing with the following error message:
2807: Missing microphone permission
I tried reverse-engineering the API a little bit and creating a custom Strategy object for BLE with a default TTL, but I instead get a 2806: FORBIDDEN
error:
private PublishOptions publishOptions() {
return new PublishOptions.Builder()
.setStrategy(strategy())
.build();
}
private Strategy strategy() {
return new Strategy.Builder()
.zze(2)
.setTtlSeconds(TTL_SECONDS_DEFAULT)
.build();
}
Why is the API requiring a microphone permission even when I've explicitly requested only BLE permissions? (fine location permissions are granted, by the way).
If you don’t have to broadcast and scan at the same time when you publish your message then modify your custom publish strategy by setting the discovery mode to “Strategy.DISCOVERY_MODE_BROADCAST”.
This plus your BLE only client should permit publishing without microphone permissions.