skip to Main Content

When I lock the screen, bluetooth does not receive data, but it still scans. I use flutter_blue_plus 1.32.4 and flutter_background_service 5.0.5.

 <uses-permission android:name="android.permission.BLUETOOTH_SCAN" android:usesPermissionFlags="neverForLocation" />
 <uses-permission android:name="android.permission.BLUETOOTH_CONNECT" />

 <!-- legacy for Android 11 or lower -->
 <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" android:maxSdkVersion="30"/>
 <uses-permission android:name="android.permission.INTERNET"/>
 <uses-permission android:name="android.permission.WAKE_LOCK" />

 <uses-permission android:name="android.permission.FOREGROUND_SERVICE"/>
 <uses-permission android:name="android.permission.FOREGROUND_SERVICE_LOCATION"/>
 <uses-permission android:name="android.permission.FOREGROUND_SERVICE_DATA_SYNC"/>

 <!-- legacy for Android 9 or lower -->
 <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" android:maxSdkVersion="28" />

2

Answers


  1. If you’re using a coroutine to process the received bluetooth data, then if your device is locked the coroutine can’t run. Coroutines require foreground state.

    You can use Google’s WorkManager to manage backgrounding. So if your device is locked all bluetooth data is processed and managed inside it.

    https://developer.android.com/develop/background-work/background-tasks/persistent/getting-started

    Just be aware that since Android 8, there is a limit for how long background processes can run (10 minutes is the max today).

    Login or Signup to reply.
  2. If you are running the app on a device below Android 12, you have to add the following permission.

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

    Also request for this permission from the app side, instead Allow while using the app choose Allow always, alternatively you can grant this permission from the app settings.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search