edufolly / flutter_bluetooth_serial

A basic Flutter Bluetooth Serial
MIT License
476 stars 455 forks source link

I add java.lang.SecurityException: Need android.permission.BLUETOOTH_CONNECT but it doesn't work #187

Open FranciscoPV94 opened 1 year ago

FranciscoPV94 commented 1 year ago

Problem summary

Apparently the problem is due to the new version of Android 12, which needs bluetooth access permissions. I am testing on a moto g50 with android 12, I tried on a moto g70 with android 11 and everything works fine.

in android docs find this https://developer.android.com/guide/topics/connectivity/bluetooth/permissions#declare-android12-or-higher

Steps to reproduce

  1. E/MethodChannel#flutter_bluetooth_serial/methods( 4896): Failed to handle method call E/MethodChannel#flutter_bluetooth_serial/methods( 4896): java.lang.SecurityException: Need android.permission.BLUETOOTH_CONNECT permission for android.content.AttributionSource@8702d63b: getName

I add java.lang.SecurityException: Need android.permission.BLUETOOTH_CONNECT but it doesn't work

Environment

flutter --version Flutter 2.2.3 • channel stable • https://github.com/flutter/flutter.git Framework • revision f4abaa0735 (1 year, 6 months ago) • 2021-07-01 12:46:11 -0700 Engine • revision 241c87ad80 Tools • Dart 2.13.4

Lauritz-Tieste commented 1 year ago

You need to uninstall the app completely from your device and reinstall it. Make sure, that you have granted all the permissions. This worked at my case (with the same error).

akhilgorantala commented 1 year ago

E/MethodChannel#flutter_bluetooth_serial/methods(15942): Failed to handle method call E/MethodChannel#flutter_bluetooth_serial/methods(15942): java.lang.SecurityException: Permission Denial: starting Intent { act=android.bluetooth.adapter.action.REQUEST_ENABLE cmp=com.oplus.wirelesssettings/com.android.settings.bluetooth.RequestPermissionActivity mCallingUid=10232 } from ProcessRecord{fdf8346 15942:com.example.bluetooth_app/u0a232} (pid=15942, uid=10232) requires android.permission.BLUETOOTH_CONNECT

MazenCoder commented 1 year ago

Same issue, also not working on the release mode

tomc128 commented 1 year ago

Have you explicitly requested the permission from within the app? From that Android developer website link:

The BLUETOOTH_ADVERTISE, BLUETOOTH_CONNECT, and BLUETOOTH_SCAN permissions are runtime permissions. Therefore, you must explicitly request user approval in your app before you can look for Bluetooth devices, make a device discoverable to other devices, or communicate with already-paired Bluetooth devices. When your app requests at least one of these permissions, the system prompts the user to allow your app to access Nearby devices, as shown in figure 1.

To do this, use the permission_handler plugin.