flutter-permission-handler icon indicating copy to clipboard operation
flutter-permission-handler copied to clipboard

[Bug]: Android 13: not able to get grant access for Bluetooth

Open SteMMo33 opened this issue 2 years ago • 7 comments

Please check the following before submitting a new issue.

Please select affected platform(s)

  • [X] Android
  • [ ] iOS
  • [ ] Windows

Steps to reproduce

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.ACCESS_FINE_LOCATION" />
 <uses-permission android:name="android.permission.BLUETOOTH_SCAN"  android:usesPermissionFlags="neverForLocation"/>
 <uses-permission android:name="android.permission.BLUETOOTH_CONNECT" />

    <uses-feature android:name="android.hardware.bluetooth" android:required="true"/>
    <uses-feature android:name="android.hardware.bluetooth_le" android:required="true"/>

Expected results

I expect that the Bluetooth permission is grant

Actual results

Bluetooth permission is denied. Bluetooth scan not enabled. In the debug console I see:

D/permissions_handler( 8780): Bluetooth permission missing in manifest
I/mali_gralloc( 8780): register: id=0x2fe000009c5, importpid=-1
I/flutter ( 8780): Statuses: {Permission.location: PermissionStatus.granted, Permission.bluetooth: PermissionStatus.denied, Permission.bluetoothScan: PermissionStatus.granted, Permission.bluetoothAdvertise: PermissionStatus.granted, Permission.bluetoothConnect: PermissionStatus.granted}

Code sample

Code sample
// You can request multiple permissions at once.
    Map<Permission, PermissionStatus> statuses = await [
      Permission.location,
      Permission.bluetoothConnect,
      Permission.bluetoothScan,
      Permission.bluetooth,
      Permission.bluetoothAdvertise,
    ].request();

    print("Statuses: $statuses");

Screenshots or video

Screenshots or video demonstration

[Upload media here]

Version

11.1.0

Flutter Doctor output

Doctor output
[✓] Flutter (Channel stable, 3.16.0, on macOS 12.7.1 21G920 darwin-x64, locale it-IT)
    • Flutter version 3.16.0 on channel stable at /Users/stefanomora/development/flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision db7ef5bf9f (4 weeks ago), 2023-11-15 11:25:44 -0800
    • Engine revision 74d16627b9
    • Dart version 3.2.0
    • DevTools version 2.28.2

[✓] Android toolchain - develop for Android devices (Android SDK version 34.0.0)
    • Android SDK at /Users/stefanomora/Library/Android/sdk
    • Platform android-34, build-tools 34.0.0
    • Java binary at: /Applications/Android Studio.app/Contents/jbr/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build 17.0.7+0-17.0.7b1000.6-10550314)
    • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 14.2)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Build 14C18
    • CocoaPods version 1.12.0

[✓] Chrome - develop for the web
    • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome

[✓] Android Studio (version 2023.1)
    • Android Studio at /Applications/Android Studio.app/Contents
    • Flutter plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/6351-dart
    • Java version OpenJDK Runtime Environment (build 17.0.7+0-17.0.7b1000.6-10550314)

[✓] VS Code (version 1.84.2)
    • VS Code at /Applications/Visual Studio Code.app/Contents
    • Flutter extension version 3.60.0

[✓] Connected device (3 available)
    • moto g14 (mobile) • ZY22HQZPD4 • android-arm64  • Android 13 (API 33)
    • macOS (desktop)   • macos      • darwin-x64     • macOS 12.7.1 21G920 darwin-x64
    • Chrome (web)      • chrome     • web-javascript • Google Chrome 120.0.6099.71

[✓] Network resources
    • All expected network resources are available.

• No issues found!

SteMMo33 avatar Dec 13 '23 15:12 SteMMo33

Hi @SteMMo33,

According to the log message it seems like you are missing a particular permission in your app/src/main/AndroidManifest.xml file. Based on the code snippet included in your issue description the missing permissions would be android.permission.BLUETOOTH_ADVERTISE.

Can you try adding this particular permission to your app/src/main/AndroidManifest.xml file and let us know if that helped?

mvanbeusekom avatar Dec 15 '23 09:12 mvanbeusekom

Hello, just added the additional permission but the result is the same:

D/permissions_handler(28499): Bluetooth permission missing in manifest I/mali_gralloc(28499): register: id=0x2fe00000ae1, importpid=-1 D/CompatibilityChangeReporter(28499): Compat change id reported: 78294732; UID 10233; state: DISABLED I/flutter (28499): Statues: {Permission.location: PermissionStatus.granted, Permission.bluetooth: PermissionStatus.denied, Permission.bluetoothScan: PermissionStatus.granted, Permission.bluetoothAdvertise: PermissionStatus.granted, Permission.bluetoothConnect: PermissionStatus.granted} I/flutter (28499): [scan] NoPermissionDlg

Thanks!

SteMMo33 avatar Dec 19 '23 09:12 SteMMo33

Which version of Android API that you used? I got this similar problem on API 28, and 31 but work fine on API 33, and 34 (Don't know why). Try to test your app on different Android API.

@SteMMo33

Blue-Cheesecake avatar Dec 25 '23 15:12 Blue-Cheesecake

In the SDK Manager I set Android 14.0 - API 34 rev.2 - not 34-ext8 or 34-ext10. Hope this help ..

SteMMo33 avatar Dec 29 '23 13:12 SteMMo33

@Blue-Cheesecake Now the context is:

  • running on phone with Android 13 - API 33
  • compileSdkVersion 33
  • targetSdkVersion 33

In the 'Run' window I see:

D/permissions_handler( 3216): Bluetooth permission missing in manifest
I/flutter ( 3216): Statues: {Permission.location: PermissionStatus.granted, Permission.bluetooth: PermissionStatus.denied, Permission.bluetoothScan: PermissionStatus.granted, Permission.bluetoothAdvertise: PermissionStatus.granted, Permission.bluetoothConnect: PermissionStatus.granted}
I/flutter ( 3216): [scan] NoPermissionDlg

I'm wondering why it reports 'Bluetooth permission missing in the manifest' ..

SteMMo33 avatar Jan 02 '24 10:01 SteMMo33

Hi @SteMMo33,

Sorry for the late reply (holiday got in the way). One thing I just thought of, during compile time the Android compiler will merge different AndroidManifests (including manifest specified in libraries) into one final manifest. On possibility would be that the bluetooth permission is removed during this merge proces. Luckily Android keeps a log file of the merge process which can be found in the build/app/outputs/logs folder.

Could you go through this log file to check if the bluetooth permissions are added? Alternatively feel free to share the log here so we can help analyse it (not sure if the file contains sensitive information though).

mvanbeusekom avatar Feb 08 '24 12:02 mvanbeusekom

When I'm checking permission for bluetooth on android, it seems to be denied. Trying to request it does not change it.

But I can ignore that and get permission for bluetoothScan, which works as expected...

ray007 avatar Feb 14 '24 08:02 ray007

Bluetooth permission is a legacy permission for older devices as you have in manifest android:maxSdkVersion="30"

So you are requesting a permission that you are not able to get granted since it is not there any more for your sdk. See here about bluetooth permissions: https://developer.android.com/develop/connectivity/bluetooth/bt-permissions

Is that make sense?

malgorzatakus avatar Mar 06 '24 08:03 malgorzatakus

Would be nice if such legacy permissions were recognized as such and considered automatically granted.

ray007 avatar Mar 06 '24 09:03 ray007

Thanks a lot for the link. I think it is a little complex but I'll study the official documentation. Thanks again.

SteMMo33 avatar Mar 06 '24 10:03 SteMMo33

Would be nice if such legacy permissions were recognized as such and considered automatically granted.

Problem is that the Bluetooth permission has been replaced with more fine grained permissions starting from Android API 30. In other words on API 29 and below the permission is still valid, while on API 30 you'd have to use BLUETOOTH_SCAN, BLUETOOTH_CONNECT and BLUETOOTH_ADVERTISE instead. The old BLUETOOTH permission is no longer valid, returning an automatic granted would give a false positive.

mvanbeusekom avatar Mar 06 '24 11:03 mvanbeusekom