Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Android] Bluetooth permission required twice #884

Open
1 of 2 tasks
c15yi opened this issue Aug 1, 2022 · 15 comments · May be fixed by #1415
Open
1 of 2 tasks

[Android] Bluetooth permission required twice #884

c15yi opened this issue Aug 1, 2022 · 15 comments · May be fixed by #1415
Labels
P2 Important issues not at the top of the work list. platform: android Issue is related to the Android platform. type: bug Something isn't working type: documentation Update to the documentation

Comments

@c15yi
Copy link
Contributor

c15yi commented Aug 1, 2022

🐛 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
@florissmit1
Copy link
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.

@florissmit1 florissmit1 added the type: documentation Update to the documentation label Aug 5, 2022
@c15yi
Copy link
Contributor Author

c15yi commented Aug 5, 2022

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
Copy link

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
Copy link

benjaminpaik commented Dec 25, 2022

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
Copy link
Contributor Author

c15yi commented Jan 11, 2023

@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
Copy link

appano1 commented Jan 30, 2023

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

@benjaminpaik
Copy link

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

@appano1
Copy link

appano1 commented Jan 31, 2023

@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
Copy link

@appano1 Thanks for replying.

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

@albertmoravec
Copy link

albertmoravec commented Feb 3, 2023

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.

rufman pushed a commit to rufman/flutter-permission-handler that referenced this issue Feb 10, 2023
The BLUETOOTH permission was removed in api version 30 in favor of
BLUETOOTH_SCAN, BLUETOOTH_ADVERTISE and BLUETOOTH_CONNECT.

This means that manifests targetting api version above 30 will not have
this permission set. For these versions the manifest should be checked
for the new permissions.

This change ensures that the documented behavior of the bluetooth
permission always returning `true` is true.

Fixes issues Baseflow#884
rufman pushed a commit to rufman/flutter-permission-handler that referenced this issue Feb 10, 2023
The BLUETOOTH permission was removed in api version 30 in favor of
BLUETOOTH_SCAN, BLUETOOTH_ADVERTISE and BLUETOOTH_CONNECT.

This means that manifests targetting api version above 30 will not have
this permission set. For these versions the manifest should be checked
for the new permissions.

This change ensures that the documented behavior of the bluetooth
permission always returning `true` is true.

Fixes issues Baseflow#884
rufman pushed a commit to rufman/flutter-permission-handler that referenced this issue Feb 10, 2023
The BLUETOOTH permission was removed in api version 30 in favor of
BLUETOOTH_SCAN, BLUETOOTH_ADVERTISE and BLUETOOTH_CONNECT.

This means that manifests targetting api version above 30 will not have
this permission set. For these versions the manifest should be checked
for the new permissions.

This change ensures that the documented behavior of the bluetooth
permission always returning `true` is true.

Fixes issues Baseflow#884
rufman added a commit to rufman/flutter-permission-handler that referenced this issue Feb 10, 2023
The BLUETOOTH permission was removed in api version 30 in favor of
BLUETOOTH_SCAN, BLUETOOTH_ADVERTISE and BLUETOOTH_CONNECT.

This means that manifests targetting api version above 30 will not have
this permission set. For these versions the manifest should be checked
for the new permissions.

This change ensures that the documented behavior of the bluetooth
permission always returning `true` is true.

Fixes issues Baseflow#884
@myselfuser1
Copy link

This might help https://www.youtube.com/watch?v=uMvGpBOT0ZY

@C-8
Copy link

C-8 commented Jun 21, 2023

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

@JeroenWeener JeroenWeener added platform: android Issue is related to the Android platform. type: bug Something isn't working P2 Important issues not at the top of the work list. labels Jul 3, 2023
@DevTiago
Copy link

Any update on this issue?

@alexxgarci
Copy link

@C-8 any workaround on this?

@benjaminpaik
Copy link

benjaminpaik commented Dec 11, 2023

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.

@ened ened linked a pull request Dec 11, 2024 that will close this issue
10 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
P2 Important issues not at the top of the work list. platform: android Issue is related to the Android platform. type: bug Something isn't working type: documentation Update to the documentation
Projects
None yet
Development

Successfully merging a pull request may close this issue.