Skip to content

[Android] Bluetooth permission required twice #884

@c15yi

Description

@c15yi
Contributor

🐛 Bug Report

I only want to test whether Bluetooth is turned on or off (with flutter_blue_plus), therefore I would assume that only <uses-permission android:name="android.permission.BLUETOOTH"/> would be sufficient.

However, when I request Bluetooth permission I get D/permissions_handler(27550): Bluetooth permission missing in manifest.
The same is true when there is no uses-permission entry at all.

Setting the line twice like this however works:

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

This only happens in combination with flutter_blue_plus, but since the error message is reported by this plugin I wanted to start here.

I actually can request the bluetooth state even without the permission at all on my device (android 12) but I guess it's necessary on older devices.

The problem with adding the permission twice is that Google Play refuses to accept the AABs.

Expected behaviour

Requesting/getting the permission result without error messages.

Reproduction steps

I created a small reproducing project here.
In the AndroidManifest.xml the Bluetooth permission is only added once, which leads to the error above.

Configuration

Phone: Pixel 5 with Android 12

Version: 10.0.0

Platform:

  • 📱 iOS
    🤖 Android

Activity

florissmit1

florissmit1 commented on Aug 5, 2022

@florissmit1
Contributor

Android 12's permission handling has changed, so the <uses-permission android:name="android.permission.bluetooth> must be changed, the permission is only used for devices which target API level 30 and lower. You can read more about it here; https://developer.android.com/guide/topics/connectivity/bluetooth/permissions.

I think this should be changed in the documentation of the permission handler, since the documentation is still targeting Android 11 and lower.

c15yi

c15yi commented on Aug 5, 2022

@c15yi
ContributorAuthor

Since my use case is only to check whether bluetooth is turned on or off, I actually don't need any bluetooth permission at all on no android device.

The documentation says that the android.permissions.BLUETOOTH permission is only to connect to paired devices (not really what I needed anyways).

In the end on Android I can safely ignore the Bluetooth permission handling.

But regarding the behaviour of the library it's still strange, that there is that error message.
Even when I add these permissions

<uses-permission android:name="android.permission.BLUETOOTH"
                     android:maxSdkVersion="30"/>
<uses-permission android:name="android.permission.BLUETOOTH_SCAN"/>
<uses-permission android:name="android.permission.BLUETOOTH_ADVERTISE"/>
<uses-permission android:name="android.permission.BLUETOOTH_CONNECT"/>

it still shows me this error message: D/permissions_handler(17875): Bluetooth permission missing in manifest

I updated the example repo with this for you to check.

Erhannis

Erhannis commented on Aug 17, 2022

@Erhannis

I've encountered a similar problem, but with bluetooth AND location. After duplicating the BLUETOOTH permission, I got an error "No permissions found in manifest for: []3", which number, looking at the code, maps to the location group. I then duplicated my existing location permissions, and the app then successfully asked for permissions and ran correctly. This is pretty clearly a bug in something; having the permissions present once should be sufficient, and having them present MORE than once should do nothing.

Permissions:

    <uses-permission android:name="android.permission.INTERNET"/>

    <uses-permission android:name="android.permission.BLUETOOTH" />
    <uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
    <uses-permission android:name="android.permission.BLUETOOTH_SCAN" />
    <uses-permission android:name="android.permission.BLUETOOTH_ADVERTISE" />
    <uses-permission android:name="android.permission.BLUETOOTH_CONNECT" />

    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
    <uses-permission android:name="android.permission.ACCESS_BACKGROUND_LOCATION" />

Request code:

  Map<Permission, PermissionStatus> statuses = await [
    Permission.bluetooth,
    Permission.bluetoothScan,
    Permission.bluetoothConnect,
    Permission.bluetoothAdvertise,
    Permission.location,
  ].request();

Android 12

Flutter 3.3.0-0.2.pre • channel beta • https://github.com/flutter/flutter.git
Framework • revision 7ac27ac8e6 (2 weeks ago) • 2022-08-02 14:35:08 -0700
Engine • revision d1e7dc18bf
Tools • Dart 2.18.0 (build 2.18.0-271.4.beta) • DevTools 2.15.0

benjaminpaik

benjaminpaik commented on Dec 25, 2022

@benjaminpaik

I've been struggling the the exact same issue with flutter_blue_plus for the last few days. I stumbled across your post and tried duplicating the bluetooth permission in the manifest and it worked. Another odd thing about this is that I was previously using the original flutter_blue and didn't have any manifest issues even though I didn't duplicate the permission.

c15yi

c15yi commented on Jan 11, 2023

@c15yi
ContributorAuthor

@benjaminpaik, if I remember correctly there were issues with release builds when having the permission set twice in the manifest. So that is not really a workaround.

appano1

appano1 commented on Jan 30, 2023

@appano1

In my case I got same error before flutter 3.7.0.
After updating flutter version to 3.7.0, the error disappeared.. 😂

benjaminpaik

benjaminpaik commented on Jan 31, 2023

@benjaminpaik

@appano1 Hmm. I just tried upgrading to flutter 3.7.0 as well and I still have permission issues.

appano1

appano1 commented on Jan 31, 2023

@appano1

@benjaminpaik Try this..!

flutter: 3.7.0
permission_handler: ^10.0.2

AndroidManifest.xml

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

    <!-- Bluetooth permission for Android sdk version > 30 -->
    <uses-permission android:name="android.permission.BLUETOOTH_SCAN" />
    <uses-permission android:name="android.permission.BLUETOOTH_ADVERTISE" />
    <uses-permission android:name="android.permission.BLUETOOTH_CONNECT" />

in your dart file

// If the Android version is higher than 30,
await [
  Permission.bluetoothConnect,
  Permission.bluetoothScan,
  Permission.bluetoothAdvertise,
].request();
benjaminpaik

benjaminpaik commented on Feb 1, 2023

@benjaminpaik

@appano1 Thanks for replying.

That's basically how I have it, but it still only works if I add BLUETOOTH permissions twice.

albertmoravec

albertmoravec commented on Feb 3, 2023

@albertmoravec

Duplicating the BLUETOOTH permission worked for me as well.
Couldn't it be that the first occurrence gets merged with another library's definition with maxSdkVersion version set and then the second occurrence is left as is?

My working merged AndroidManifest.xml looks like this:

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

I suspect that permission_handler is requiring manifest entries that aren't really necessary and fails with the Bluetooth permission missing in manifest message even though everything should work.

myselfuser1

myselfuser1 commented on Mar 17, 2023

@myselfuser1
C-8

C-8 commented on Jun 21, 2023

@C-8

Adding bluetooth permission twice is not working anymore. It throws error:
Element uses-permission#android.permission.BLUETOOTH at AndroidManifest.xml:6:3-66 duplicated with element declared at AndroidManifest.xml:3:3-5:36

added
platform: androidIssue is related to the Android platform.
type: bugSomething isn't working
P2Important issues not at the top of the work list.
on Jul 3, 2023
DevTiago

DevTiago commented on Nov 18, 2023

@DevTiago

Any update on this issue?

alexxgarci

alexxgarci commented on Nov 21, 2023

@alexxgarci

@C-8 any workaround on this?

benjaminpaik

benjaminpaik commented on Dec 11, 2023

@benjaminpaik

Adding bluetooth permission twice is not working anymore. It throws error: Element uses-permission#android.permission.BLUETOOTH at AndroidManifest.xml:6:3-66 duplicated with element declared at AndroidManifest.xml:3:3-5:36

I just tested my old project upgrading to Flutter 3.16.3 and permission_handler 11.1.0. Adding BLUETOOTH to the manifest twice still works for me. Perhaps it was broken and then fixed in a recent update.

linked a pull request that will close this issue on Dec 11, 2024
PhillipMahlke-flour

PhillipMahlke-flour commented on May 15, 2025

@PhillipMahlke-flour

Can we get this pr merged, if it fixes this problem?

While adding the permissions twice does work, Google Play Store does not allow this workaround and prevents the appbundle to be released, if it has the bluetooth permissions twice.

Should not be marked as P2, if it literally prevents publishing of apps. Should be marked as P0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2Important issues not at the top of the work list.platform: androidIssue is related to the Android platform.type: bugSomething isn't workingtype: documentationUpdate to the documentation

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      Participants

      @Erhannis@albertmoravec@benjaminpaik@JeroenWeener@alexxgarci

      Issue actions

        [Android] Bluetooth permission required twice · Issue #884 · Baseflow/flutter-permission-handler