-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Requesting Bluetooth permissions on Android 12+ at runtime #12264
Description
Description
Microsoft.Maui.ApplicationModel.Permissions contains support for all kind of runtime permissions, but it is currently missing support for Android 12 Bluetooth permissions, see https://developer.android.com/guide/topics/connectivity/bluetooth/permissions.
Previous to Android 12, a runtime request was not necessary for the Bluetooth permissions (only the location permission needed to be requested at runtime). With Android 12, the Bluetooth permission scheme was changed, and now there are three kinds of Bluetooth permissions that can be requested at runtime: BLUETOOTH_ADVERTISE, BLUETOOTH_CONNECT and BLUETOOTH_SCAN.
This was already requested for Xamarin.Essentials, see xamarin/Essentials#1943, but never implemented, apparently.
Public API Changes
The following kinds of requests should be possible:
PermissionStatus s1 = await Permissions.RequestAsync<Permissions.BluetoothAdvertise>();
PermissionStatus s2 = await Permissions.RequestAsync<Permissions.BluetoothConnect>();
PermissionStatus s3 = await Permissions.RequestAsync<Permissions.BluetoothScan>();Potentially also a way to bundle them would be useful (requesting two or more of them with a single call).
Intended Use-Case
This is relevant for any app that uses Bluetooth functionality (e.g. via https://github.com/dotnet-bluetooth-le/dotnet-bluetooth-le) and targets Android 12 or later.
The sample app in dotnet-bluetooth-le currently works around this, see dotnet-bluetooth-le/dotnet-bluetooth-le#582.