pythonandroidbluetoothpyjniuspython-for-android

Bluetooth permissions checks is not working but WiFi does


I have a problem with validating permissions on a press of a button in Python using Python-for-Android/Pyjnius and Kivy.

from android.permissions import check_permission
# Checks permissions returns True if app has permission
if check_permission('android.permission.ACCESS_FINE_LOCATION'):
   # [...] wifi scan code

Above works as intended, on app install it requests access to fine location, I hit accept, turn the app on scanning networks works as intended moment I turn it off, it displays a message on the RecycleView that Permissions were denied.

But, bluetooth checks are a different story.

from android.permissions import check_permission, Permission
# Check permission returns True if app has all permissions
permissions = [Permission.BLUETOOTH_SCAN, Permission.BLUETOOTH_CONNECT, Permission.ACCESS_FINE_LOCATION]
granted = True
for permission in permissions:
    granted = granted and check_permission(permission)

if granted:
   # [...] bluetooth code scan

When I have the app not validating permissions it runs fine, moment I put them in Permissions are denied although in our separate request_permissions.py script we request these on the app's build and our buildozer.spec also has these permissions in there.

Important to note that both our functions responsible for scanning are put into individual Threads, but even then why WiFi works but Bluetooth isn't?

On my hardware, Samsung S9 - Android 10 it never asks for Bluetooth permissions although the scanner works but will ask for ACCESS_FINE_LOCATION permissions on first time app launch.

Would anyone know why this is?


Solution

  • Well, turns out my phone being Android 10 was the issue. In accordance with Android API docs you need extra additional permissions.

    https://developer.android.com/develop/connectivity/bluetooth/bt-permissions