<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="https://devzone.nordicsemi.com/cfs-file/__key/system/syndication/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Android: Problem with BLE scanning stopped while screen is off on newer phones</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/117280/android-problem-with-ble-scanning-stopped-while-screen-is-off-on-newer-phones</link><description>Hello, 
 
 We&amp;#39;re using the Scanner Compat (v1.6.0) library for Android in our app, and it has helped us tremendously. 
 
 Recently we&amp;#39;ve observed that the Xiaomi 12T has stopped delivering scan results with the screen off. This means that users cannot</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Tue, 07 Jan 2025 08:29:59 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/117280/android-problem-with-ble-scanning-stopped-while-screen-is-off-on-newer-phones" /><item><title>RE: Android: Problem with BLE scanning stopped while screen is off on newer phones</title><link>https://devzone.nordicsemi.com/thread/517145?ContentTypeID=1</link><pubDate>Tue, 07 Jan 2025 08:29:59 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:0b6b75b1-a659-4dcb-8d17-48e272387639</guid><dc:creator>Simonr</dc:creator><description>&lt;p&gt;Hey Robin&lt;/p&gt;
&lt;p&gt;I ran Emil&amp;#39;s suggestion and your concern by one of our mobile devs as well, and they agree with you. The only method of connecting without the app running in the foreground is by scanning with PendingIntent. The system then calls this intent when a device is found and it can notify the user/take action. A connectGatt without the PendingIntent will be stopped when the app gets killed/closed.&lt;/p&gt;
&lt;p&gt;Best regards,&lt;/p&gt;
&lt;p&gt;Simon&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Android: Problem with BLE scanning stopped while screen is off on newer phones</title><link>https://devzone.nordicsemi.com/thread/516917?ContentTypeID=1</link><pubDate>Mon, 06 Jan 2025 08:25:38 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:a3336006-ff1b-407e-b835-88195a7dc4dc</guid><dc:creator>RobinDev</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;Interesting suggestion. We do know the paired device&amp;#39;s MAC address, so we could actually try this approach.&lt;/p&gt;
&lt;p&gt;However, wouldn&amp;#39;t you need the app running at all times as a foreground service to have this work? Because that would negate the benefit of using Intents for scanning.&lt;/p&gt;
&lt;p&gt;Regards,&lt;/p&gt;
&lt;p&gt;Robin&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Android: Problem with BLE scanning stopped while screen is off on newer phones</title><link>https://devzone.nordicsemi.com/thread/516028?ContentTypeID=1</link><pubDate>Sat, 21 Dec 2024 09:07:18 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:74b640d0-bfde-4930-bf29-4e7ed5196357</guid><dc:creator>Emil Lenngren</dc:creator><description>&lt;p&gt;Do you want to connect to devices where you already know the Bluetooth device address? In that case you can instead have a long running pending connection. Call connectGatt with autoConnect parameter set to true.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Android: Problem with BLE scanning stopped while screen is off on newer phones</title><link>https://devzone.nordicsemi.com/thread/515903?ContentTypeID=1</link><pubDate>Fri, 20 Dec 2024 11:33:41 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:5d0b0d66-95aa-495f-9046-7d51ee92b0b2</guid><dc:creator>RobinDev</dc:creator><description>&lt;p&gt;Hello,&lt;/p&gt;
&lt;p&gt;We&amp;#39;re glad you&amp;#39;re taking time to look further into this issue.&lt;/p&gt;
&lt;p&gt;I also don&amp;#39;t belive it&amp;#39;s a hard requirement to use scanDelay for intent scanning in the background, because, as already mentioned, we have a lot of happy customers using the product as it was designed.&lt;/p&gt;
&lt;p&gt;However, I did manage to dig up the place where Google makes a comment on using reportDelay with intent scanning in one of their &lt;a href="https://github.com/android/platform-samples/blob/cd837457bd7cd865141d10774b0f4b064e18c72f/samples/connectivity/bluetooth/ble/src/main/java/com/example/platform/connectivity/bluetooth/ble/BLEScanIntentSample.kt#L171C1-L172C30"&gt;BLE samples&lt;/a&gt;. Also, in the &lt;a href="https://github.com/NordicSemiconductor/Android-Scanner-Compat-Library?tab=readme-ov-file#background-scanning-guidelines"&gt;background scanning guidelines&lt;/a&gt; of the Scanner Compat library, it is mentioned that reportDelay should be used. That&amp;#39;s all I have to go off of. If there are nuances to this that I&amp;#39;m missing, please feel free to enlighten me - that&amp;#39;s why I&amp;#39;m here &lt;span class="emoticon" data-url="https://devzone.nordicsemi.com/cfs-file/__key/system/emoji/1f642.svg" title="Slight smile"&gt;&amp;#x1f642;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;Please reach out if you need anything in the testing. The implementation of the Xiaomi phone is somewhat quirky, so there could be some challenges in successfully reproducing the problem. In that case I can provide som repro steps that brings out the problem for us at least.&lt;/p&gt;
&lt;p&gt;Regards,&lt;/p&gt;
&lt;p&gt;Robin&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Android: Problem with BLE scanning stopped while screen is off on newer phones</title><link>https://devzone.nordicsemi.com/thread/515758?ContentTypeID=1</link><pubDate>Thu, 19 Dec 2024 13:55:12 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:b03abbbc-6146-4999-b04c-c6c637ff4fdd</guid><dc:creator>Simonr</dc:creator><description>&lt;p&gt;Hi Robin&lt;/p&gt;
&lt;p&gt;So, I talked to one of our mobile apps devs today, and as far as they know there aren&amp;#39;t ant specific requirement for batching (delayReport). We don&amp;#39;t have a project up to do background scanning at the moment, and we will have to take a better look at this after the Christmas holiday.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Sorry that we couldn&amp;#39;t provide a quick and easy solution to this, but please keep us posted if you find anything or find more mobile devices where this issue is seen too.&lt;/p&gt;
&lt;p&gt;Best regards,&lt;/p&gt;
&lt;p&gt;Simon&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Android: Problem with BLE scanning stopped while screen is off on newer phones</title><link>https://devzone.nordicsemi.com/thread/515487?ContentTypeID=1</link><pubDate>Wed, 18 Dec 2024 12:55:11 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:c9db5616-e15e-49a9-bf49-08319dbce889</guid><dc:creator>RobinDev</dc:creator><description>&lt;p&gt;Hello&lt;/p&gt;
&lt;p&gt;Thank you for looking into it.&lt;/p&gt;
&lt;p&gt;One of our beta-testers has reported seeing the same behavior on Xiaomi 14 (likely also the 13), suggesting that this is a trend that Xiaomi is continuing, unfortunately. We&amp;#39;ve also heard similar story from our support department regarding the new OnePlus 12.&lt;/p&gt;
&lt;p&gt;Regards&lt;/p&gt;
&lt;p&gt;Robin&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Android: Problem with BLE scanning stopped while screen is off on newer phones</title><link>https://devzone.nordicsemi.com/thread/515477?ContentTypeID=1</link><pubDate>Wed, 18 Dec 2024 12:38:52 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:03494b68-dc92-4aa5-8540-b15b0eb50772</guid><dc:creator>Simonr</dc:creator><description>&lt;p&gt;Hi Robin&lt;/p&gt;
&lt;p&gt;Thank you for the thorough feedback. I&amp;#39;ll run this concern by our mobile apps group and get back to you. Do you also have a list of other models that you&amp;#39;re seeing this issue with, as I know we have various OnePlus mobiles available in office, but not too many Xiaomi&amp;#39;s.&lt;/p&gt;
&lt;p&gt;Best regards,&lt;/p&gt;
&lt;p&gt;Simon&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Android: Problem with BLE scanning stopped while screen is off on newer phones</title><link>https://devzone.nordicsemi.com/thread/515392?ContentTypeID=1</link><pubDate>Wed, 18 Dec 2024 07:54:58 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:54c7e795-0343-40d4-85f2-cb7a1516bf0e</guid><dc:creator>RobinDev</dc:creator><description>&lt;p&gt;Hello&lt;/p&gt;
&lt;p&gt;Absolutely! But let me be clear, our setup has worked - and is working - as expected on many phones that we support. What we&amp;#39;re seeing lately, however, is a worrying trend where that this setup doesn&amp;#39;t work anymore on certain phones, including, but presumably not limited to, the Xiaomi12T we use for testing. More precisely, we&amp;#39;ve heard complaints from Xiaomi and OnePlus customers, experiencing the same behavior: Not connecting automatically anymore with the screen off. Briefly activating the screen, however, triggers the expected instant connection.&lt;/p&gt;
&lt;p&gt;As mentioned earlier, it seems non-batched scans with PendingIntents are being suppressed with the screen off, and even performing batched scanning via the reportDelay scan setting puts the scan results on a fixed 5 min timer. This might be fine for a smart watch that periodically syncs throughout the day, but not for our devices where an instant automatic connection is part of the core functionality.&lt;/p&gt;
&lt;p&gt;Here&amp;#39;s the filter definition:&lt;/p&gt;
&lt;div style="background-color:#1e1f22;color:#a9b7c6;"&gt;
&lt;pre style="font-family:&amp;#39;Fira Code&amp;#39;,monospace;font-size:12,0pt;"&gt;&lt;span style="color:#cf8e6d;"&gt;private val &lt;/span&gt;&lt;span style="color:#c77dbb;"&gt;SCAN_FILTER &lt;/span&gt;&lt;span style="color:#bcbec4;"&gt;= &lt;/span&gt;&lt;span style="font-style:italic;"&gt;listOf&lt;/span&gt;&lt;span style="color:#bcbec4;"&gt;(&lt;br /&gt;&lt;/span&gt;&lt;span style="color:#bcbec4;"&gt;        ScanFilter.Builder()&lt;br /&gt;&lt;/span&gt;&lt;span style="color:#bcbec4;"&gt;                .setServiceUuid(ParcelUuid.fromString(&amp;lt;service UUID 1&amp;gt;&lt;/span&gt;&lt;span style="color:#bcbec4;"&gt;)&lt;br /&gt;&lt;/span&gt;&lt;span style="color:#bcbec4;"&gt;                .build(),&lt;br /&gt;&lt;/span&gt;&lt;span style="color:#bcbec4;"&gt;        ScanFilter.Builder()&lt;br /&gt;&lt;/span&gt;&lt;span style="color:#bcbec4;"&gt;                .setServiceUuid(ParcelUuid.fromString(&amp;lt;service UUID 2&amp;gt;&lt;/span&gt;&lt;span style="color:#bcbec4;"&gt;)&lt;br /&gt;&lt;/span&gt;&lt;span style="color:#bcbec4;"&gt;                .build(),&lt;br /&gt;&lt;/span&gt;&lt;span style="color:#bcbec4;"&gt;        ScanFilter.Builder()&lt;br /&gt;&lt;/span&gt;&lt;span style="color:#bcbec4;"&gt;                .setServiceUuid(ParcelUuid.fromString(&amp;lt;service UUID 3&amp;gt;&lt;/span&gt;&lt;span style="color:#bcbec4;"&gt;)&lt;br /&gt;&lt;/span&gt;&lt;span style="color:#bcbec4;"&gt;                .build())&lt;/span&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;and the use site:&lt;/p&gt;
&lt;div style="background-color:#1e1f22;color:#a9b7c6;"&gt;
&lt;pre style="font-family:&amp;#39;Fira Code&amp;#39;,monospace;font-size:12,0pt;"&gt;&lt;span style="color:#cf8e6d;"&gt;override fun &lt;/span&gt;&lt;span style="color:#56a8f5;"&gt;startScan&lt;/span&gt;&lt;span style="color:#bcbec4;"&gt;() {&lt;br /&gt;&lt;/span&gt;&lt;span style="color:#bcbec4;"&gt;    BluetoothLeScannerCompat.getScanner().startScan(&lt;/span&gt;&lt;span style="color:#c77dbb;"&gt;SCAN_FILTER&lt;/span&gt;&lt;span style="color:#bcbec4;"&gt;, &lt;/span&gt;&lt;span style="color:#c77dbb;"&gt;SCAN_SETTINGS&lt;/span&gt;&lt;span style="color:#bcbec4;"&gt;, &lt;/span&gt;&lt;span style="color:#c77dbb;"&gt;context&lt;/span&gt;&lt;span style="color:#bcbec4;"&gt;,&lt;br /&gt;&lt;/span&gt;&lt;span style="color:#bcbec4;"&gt;            &lt;/span&gt;&lt;span style="color:#c77dbb;"&gt;scanningPendingIntent&lt;/span&gt;&lt;span style="color:#bcbec4;"&gt;, &lt;/span&gt;&lt;span style="color:#c77dbb;"&gt;RC_START_STOP_SCANNING&lt;/span&gt;&lt;span style="color:#bcbec4;"&gt;)&lt;br /&gt;&lt;/span&gt;&lt;span style="color:#bcbec4;"&gt;}&lt;/span&gt;&lt;/pre&gt;
&lt;/div&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Android: Problem with BLE scanning stopped while screen is off on newer phones</title><link>https://devzone.nordicsemi.com/thread/515318?ContentTypeID=1</link><pubDate>Tue, 17 Dec 2024 15:36:56 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:8e2ecbda-62f5-4adf-841a-cc7a139c6baa</guid><dc:creator>Simonr</dc:creator><description>&lt;p&gt;Hi Robin&lt;/p&gt;
&lt;p&gt;Can you show me how you&amp;#39;ve set the filter in your application so I can run it by one of our mobile devs?&lt;/p&gt;
&lt;p&gt;Best regards,&lt;/p&gt;
&lt;p&gt;Simon&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Android: Problem with BLE scanning stopped while screen is off on newer phones</title><link>https://devzone.nordicsemi.com/thread/515161?ContentTypeID=1</link><pubDate>Mon, 16 Dec 2024 15:04:14 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:603b0b58-e3fc-49e1-923a-64d2df4d82d4</guid><dc:creator>RobinDev</dc:creator><description>&lt;p&gt;Hello,&lt;/p&gt;
&lt;p&gt;Thank you for your answer.&lt;/p&gt;
&lt;p&gt;I&amp;#39;m well aware that what you describe is the expected behavior when scanning without filters. However, we are scanning with filters, which makes the behvior we&amp;#39;re seeing very unexpected.&lt;/p&gt;
&lt;p&gt;Regards,&lt;/p&gt;
&lt;p&gt;Robin&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Android: Problem with BLE scanning stopped while screen is off on newer phones</title><link>https://devzone.nordicsemi.com/thread/515158?ContentTypeID=1</link><pubDate>Mon, 16 Dec 2024 14:57:43 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:d12a0478-ed18-4e12-9bfc-d4f3f04ca33f</guid><dc:creator>Simonr</dc:creator><description>&lt;p&gt;Hi&lt;/p&gt;
&lt;p&gt;In the&lt;a href="https://github.com/NordicSemiconductor/Android-Scanner-Compat-Library"&gt; Android Scanner Compat library&lt;/a&gt; readme file the following is stated: &amp;quot;&lt;em&gt;F&lt;/em&gt;&lt;span&gt;&lt;em&gt;or unfiltered scans, scanning is stopped on screen off to save power. Scanning is resumed when screen is turned on again. To avoid this, use scanning with desired ScanFilter.&lt;/em&gt;&amp;quot;&amp;nbsp;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Best regards,&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Simon&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Android: Problem with BLE scanning stopped while screen is off on newer phones</title><link>https://devzone.nordicsemi.com/thread/515157?ContentTypeID=1</link><pubDate>Mon, 16 Dec 2024 14:56:19 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:092d83be-0d16-4da4-95e3-e2aae714b9a4</guid><dc:creator>RobinDev</dc:creator><description>&lt;p&gt;Hello.&lt;/p&gt;
&lt;p&gt;Thank you for the prompt answer.&lt;/p&gt;
&lt;p&gt;As to my understanding, the PendingIntent based scanning should allow for scanning in the background while the app isn&amp;#39;t active. This approach has also worked for us with other phone models, and, if my memory serves me right, also the Xiaomi12T before an update. Also, we have background_location permissions, as well as the ignoreBatteryOptimization, so the app should be (relatively) uninhibited by power saving mechanisms, even in background.&lt;/p&gt;
&lt;p&gt;Lately, however, as described in my oroginal post, it seems a new behavior has implemented in at least some newer phones, where non-batched scanning is entirely suspended while the screen is off. And in the case of the Xiaomi12T at least, batched scan results are only propagated to apps once every 5 minuts.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Android: Problem with BLE scanning stopped while screen is off on newer phones</title><link>https://devzone.nordicsemi.com/thread/515002?ContentTypeID=1</link><pubDate>Sun, 15 Dec 2024 21:30:15 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:63beaf50-560e-4967-a689-8b7d1bc71b33</guid><dc:creator>snoopy20</dc:creator><description>&lt;p&gt;With the screen off I believe your App has to be set to run in the background or it gets paused. I haven&amp;#39;t looked into it though.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>