Google's NearbyMessages API with only BLE Permissions is asking for Microphone Permission

361 views Asked by At

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).

2

There are 2 answers

0
GreenRollingHills On

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”.

private Strategy strategy() {
    return new Strategy.Builder()
            .setDiscoveryMode(Strategy.DISCOVERY_MODE_BROADCAST)
            .setTtlSeconds(TTL_SECONDS_DEFAULT)
            .build();
}

This plus your BLE only client should permit publishing without microphone permissions.

1
Morrison Chang On

From the Nearby Messages API Overview:

Nearby uses a combination of Bluetooth, Bluetooth Low Energy, Wi-Fi and near-ultrasonic audio to communicate a unique-in-time pairing code between devices.

So the API you are using is expecting to speak and listen with audio for nearby identification/messaging.