Skip to main content

Asking Runtime Permissions (ANDROID-Flutter)

This guide helps asking runtime permissions in Flutter framework.​

Some Android permissions must be asked depending on the Android version of the user. If the user has an Android version.

Permissions for Android 6.0 and above:

  Future<void> _checkPermissionsLocation() async {
DeviceInfoPlugin deviceInfoPlugin = DeviceInfoPlugin();
final androidInfo = await deviceInfoPlugin.androidInfo;
var sdkInt = androidInfo.version.sdkInt;
if(sdkInt>=29) {
//Grouplink Requirements:
//Android needs only while in use location.
//Optional: show a rationale why the permission is used in your app.
var statuses = await Permission.location.request();
if (statuses.isDenied) {
//Optional: reiterates with a rationale why the permission is used and needed in your app.
statuses = await Permission.location.request();
}
}
}

For Android 12 there are new situational bluetooth permissions. All of the following are needed. Permissions for Android 12:

  Future<void> _checkPermissionBluetooth() async {
DeviceInfoPlugin deviceInfoPlugin = DeviceInfoPlugin();
final androidInfo = await deviceInfoPlugin.androidInfo;
var sdkInt = androidInfo.version.sdkInt;
if(sdkInt>=31) {
//Optional: show a rationale why the permission is used in your app.
var statuses = await [
Permission.bluetoothScan,
Permission.bluetoothAdvertise,
Permission.bluetoothConnect
].request();
if (statuses[Permission.bluetoothScan]!.isDenied) {
//Optional: reiterates with a rationale why the permission is used and needed in your app.
statuses = await [
Permission.bluetoothScan,
Permission.bluetoothAdvertise,
Permission.bluetoothConnect
].request();
}
}
}