Flutter, Android 12 not discovering Beacons

Viewed 732

I'm using flutter_blue_plus package to scan BLE devices. And I am using permission_handler plugin to handle permissions.

The app works perfectly fine in Android 11 or lower. However in Android 12, plugin discovers other ble devices but not Beacons.

I have following lines in AndroidManifest.xml

<uses-permission android:name="android.permission.BLUETOOTH"
                     android:maxSdkVersion="30" />
    <uses-permission android:name="android.permission.BLUETOOTH_ADMIN"
                     android:maxSdkVersion="30" />

   
    <uses-permission android:name="android.permission.BLUETOOTH_SCAN" android:usesPermissionFlags="neverForLocation" />

    <!-- Needed only if your app communicates with already-paired Bluetooth
         devices. -->
    <uses-permission android:name="android.permission.BLUETOOTH_CONNECT" />
    <uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
    <uses-permission android:name="android.permission.ACCESS_BACKGROUND_LOCATION"/>
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />

I also tried removing android:usesPermissionFlags="neverForLocation" in BLUETOOTH_SCAN permission.

And before starting scan, I have handled permission in following ways

final permissionBT = await Permission.bluetooth.request().isGranted;
    final permissionBTScan = await Permission.bluetoothScan.request().isGranted;
    final permissionBTConnect =
        await Permission.bluetoothConnect.request().isGranted;
    final permissionBTAd =
        await Permission.bluetoothAdvertise.request().isGranted;
    final permissionLoc = await Permission.location.request().isGranted;
    final permissionLocALways =
        await Permission.locationAlways.request().isGranted;
    final permissionLocInUse = await Permission.locationWhenInUse.request().isGranted;
    //code to start scan.

Can anybody tell me what I am missing?

1 Answers

Go to the app settings, and where it says Permissions, manually select "nearby devices", and it will detect it. The big problem is that I don't know why you have to do it manually.

Related