Reputation: 1793
Nothing to do with scanning. I am already connected and have a foreground service.
It seems that BLE communications are blocked when the screen is turned off and unplugged from a charger.
Is there a way to keep communications active/permitted? From what I understand, BLE comms should never be blocked by the OS, even in Doze modes.
As soon as I wake the lock screen, the pending communications appear to all come through. The logs show that no BLE disconnections occurred while the screen was off but they also show that the BLE data only came through once the screen was awake. This is obviously not being sent form the host only when the screen is on as it works correctly while plugged in. (i.e. the host is correctly sending the event).
It is immediate, as in as soon as I turn the screen off (and it's unlplugged from the charger), initiating BLE comms from the host device will be ignored until the screen is woken or the device plugged in.
All known power saving / battery optimizations are off, but the doze prompt has not been requested to the user, although it shouldn't be doze if the comms are blocked immediately, apps don't get put to sleep/doze mode immediately afaik.
I've added a beep sound to be played when the BLE data is received but I only hear it after about 60 seconds from when it should actually have been received, or if I wake the device or plug it in. Sometimes it's around 20 seconds randomly.
I can connect multiple devices and the one's with their screen on all receive it while the one's with the screens off do not. What am I missing here? Since when does BLE get blocked when the screen is off?
Even if I add the doze prompt and prevent doze restrictions, the same behaviour is seen.
Devices: Samsung A23 - Android 13 Pixel 5 - Android 14
Foreground service code:
val startIntent = Intent(context, XService::class.java)
ContextCompat.startForegroundService(context, startIntent)
and the notification from the service code:
val notificationIntent = Intent(this, MainActivity::class.java)
val pendingIntent = PendingIntent.getActivity(
this,
SERVICE_NOTIFICATION_REQUEST_CODE, notificationIntent, FLAG_IMMUTABLE
)
val notification = NotificationCompat.Builder(this, getString(R.string.notification_serviceChannelId))
.setPriority(NotificationCompat.PRIORITY_LOW)
.setContentTitle(notificationTitle)
.setSmallIcon(notificationIconResourceId)
.setContentIntent(pendingIntent)
.setOngoing(true)
.setAutoCancel(false)
.setGroup(X_SERVICE_NOTIFICATION_GROUP_ID)
.setGroupSummary(true)
.build()
startForeground(X_SERVICE_NOTIFICATION_ID, notification)
Upvotes: 0
Views: 303
Reputation: 64
It feels like your service is running in background mode. Can you confirm you called the startForeground
function from the service?
Upvotes: 0