<?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>BLE connection to Android mobile phone</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/82535/ble-connection-to-android-mobile-phone</link><description>Hi, 
 I&amp;#39;m using NRF52840 to connect to an Android mobile phone. 
 The application scans for advertisement and when the NRF device starts advertising - connection is established. 
 
 The problem is that after bonding - connection isn&amp;#39;t always established</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Thu, 09 Dec 2021 14:52:45 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/82535/ble-connection-to-android-mobile-phone" /><item><title>RE: BLE connection to Android mobile phone</title><link>https://devzone.nordicsemi.com/thread/342755?ContentTypeID=1</link><pubDate>Thu, 09 Dec 2021 14:52:45 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:a1292271-a15a-4be4-94c7-94e4a8aecf82</guid><dc:creator>Roei</dc:creator><description>&lt;p&gt;Thanks!!&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: BLE connection to Android mobile phone</title><link>https://devzone.nordicsemi.com/thread/342713?ContentTypeID=1</link><pubDate>Thu, 09 Dec 2021 12:44:10 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:10be02e1-d8f1-4eae-a2c3-d57145876851</guid><dc:creator>Aleksander Nowakowski</dc:creator><description>&lt;p&gt;The address is saved on the device side in whitelist butter, yes. But I&amp;#39;m completely not an expert when it comes to embedded, so I don&amp;#39;t know how it&amp;#39;s done. Perhaps automatic by the peer manager.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: BLE connection to Android mobile phone</title><link>https://devzone.nordicsemi.com/thread/342712?ContentTypeID=1</link><pubDate>Thu, 09 Dec 2021 12:42:53 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:4fc71e15-25f1-467d-9a22-b2a113cb3d4b</guid><dc:creator>Aleksander Nowakowski</dc:creator><description>&lt;p&gt;Still, you need to scan on Android, and when you get a scan result, you need to connect. Direct advertising has this advantage, that it&amp;#39;s very fast, but lasts only for 1.25 sec after boot, so I understand it&amp;#39;s good for quick reconnections. After that the device start advertising with a whitelist.&lt;/p&gt;
&lt;p&gt;On Android, you may call connectGatt method with autoConnect param set to true. This should keep make Android automatically reconnect if needed, but you cannot close the returned BluetoothGatt object. So for a long running operation you&amp;#39;d have to have a foreground service that holds this object and awaits connection. In practice, on Android 8+ it&amp;#39;s better to scan using a PendingIntent with correct filter. You don&amp;#39;t need to have the service in that case and your app can be even killed. When the device is scanner, you&amp;#39;ll get the Intent which can launch BroadcastReceiver, or a Service, from which you may promote the serivce to foreground and connect to the device with autoConnect&amp;nbsp; = true.&lt;/p&gt;
&lt;p&gt;Actually, we should do such sample, as it&amp;#39;s quite common. I&amp;#39;ll add it to our backlog.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: BLE connection to Android mobile phone</title><link>https://devzone.nordicsemi.com/thread/342691?ContentTypeID=1</link><pubDate>Thu, 09 Dec 2021 11:49:46 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:a36fd960-0c96-4d23-94fd-6ec428308797</guid><dc:creator>Roei</dc:creator><description>&lt;p&gt;Thank you Aleksander!&lt;/p&gt;
&lt;p&gt;I think I understand now.&lt;/p&gt;
&lt;p&gt;Yes - I can see that there is a directed advertising in the example. Do you think it can help me to connect via Android even when the app isn&amp;#39;t open?&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;As far as I understand - direct advertising requires saving of peer&amp;#39;s BLE address, isn&amp;#39;t it?&lt;/p&gt;
&lt;p&gt;It can&amp;#39;t help me if the peer changes its address.&lt;/p&gt;
&lt;p&gt;Am I right?&lt;/p&gt;
&lt;p&gt;Thanks!&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: BLE connection to Android mobile phone</title><link>https://devzone.nordicsemi.com/thread/342689?ContentTypeID=1</link><pubDate>Thu, 09 Dec 2021 11:39:26 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:95094915-f0e8-4981-9469-954233a2880a</guid><dc:creator>Aleksander Nowakowski</dc:creator><description>&lt;p&gt;HID stands for Human Interface Device, which is a keyboard, mouse, a joystick, etc. Input from such devices is supported by Android, so you may connect your keyboard to the phone/tablet and use it instead of soft keyboard (displayed on the screen). The example you mentioned, &lt;span&gt;ble_app_hids_keyboard, demonstrates how to implement such. But if you&amp;#39;re not working on such device, you should rather look into how this sample is advertising. Have a look at advertising_init method (if you&amp;#39;re using nRF5 SDK) and see that the keyboard sample is using directed advertising.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;I&amp;#39;m now trying to implement the same in Proximity sample, which is not natively supported by Android, and see it the phone connects to it automatically as well without any app asking for it.&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: BLE connection to Android mobile phone</title><link>https://devzone.nordicsemi.com/thread/342687?ContentTypeID=1</link><pubDate>Thu, 09 Dec 2021 11:31:58 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:94dab2f8-6f4c-4194-818b-aeec522aa4ba</guid><dc:creator>Roei</dc:creator><description>&lt;p&gt;Hi Aleksander, thank you for your answer!&lt;/p&gt;
&lt;p&gt;Can you please explain a little bit more about the HID profile?&lt;/p&gt;
&lt;p&gt;What does it do? Can it help me with my issue? How can I define it on my NRF code?&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Thanks!&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: BLE connection to Android mobile phone</title><link>https://devzone.nordicsemi.com/thread/342679?ContentTypeID=1</link><pubDate>Thu, 09 Dec 2021 11:00:30 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:b3cccfa3-d9fd-417a-aef6-38ddcbf02b89</guid><dc:creator>Aleksander Nowakowski</dc:creator><description>&lt;p&gt;Hello,&lt;/p&gt;
&lt;p&gt;The automatic connection can be established in several ways. After bonding, the device could advertise directly, which should trigger Android reconnecting to the device. But then, you should have an app ready to take over the connection. For HID profiles, like keyboard and mouse, that is not needed, as it&amp;#39;s supported natively since KitKat. Other profiles need to have an app, and the app need to be running or woken up by the system.&lt;/p&gt;
&lt;p&gt;On Android O and newer, you may scan with &lt;a href="https://developer.android.com/reference/android/bluetooth/le/BluetoothLeScanner#startScan(java.util.List%3Candroid.bluetooth.le.ScanFilter%3E,%20android.bluetooth.le.ScanSettings,%20android.app.PendingIntent)" rel="noopener noreferrer" target="_blank"&gt;PendingIntent&lt;/a&gt;, which will allow your app not to have any long running service. When the device is found, the system can wake up your app by calling a broadcast, or perhaps starting a service, that should connect to the device.&lt;/p&gt;
&lt;p&gt;You may also use a background service that does the scanning, but those may be killed if the service is not displaying a notification (isn&amp;#39;t promoted to foreground service). Have a look at &lt;a href="https://developer.android.com/about/versions/oreo/background"&gt;https://developer.android.com/about/versions/oreo/background&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;Nordic offers &lt;a href="https://github.com/NordicSemiconductor/Android-Scanner-Compat-Library" rel="noopener noreferrer" target="_blank"&gt;Android Scanner Compat Library&lt;/a&gt; which can emulate scanning with PendingIntent for older platforms, but we highly recommend setting minSdk to Android O, as this is way more battery efficient than what the compat library can deliver.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: BLE connection to Android mobile phone</title><link>https://devzone.nordicsemi.com/thread/342676?ContentTypeID=1</link><pubDate>Thu, 09 Dec 2021 10:51:49 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:a327feae-e373-4e2a-8e8a-ee66d4b89081</guid><dc:creator>Aleksander Nowakowski</dc:creator><description>&lt;p&gt;The HID profile is supported natively by Android. No other app is required.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: BLE connection to Android mobile phone</title><link>https://devzone.nordicsemi.com/thread/342669?ContentTypeID=1</link><pubDate>Thu, 09 Dec 2021 10:16:13 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:7bfb263b-9421-4c64-821a-bda1193204fd</guid><dc:creator>Roei</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;I&amp;#39;ve read about&amp;nbsp;&lt;span&gt;ble_app_hids_keyboard - can you please tell me what is special about it?&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Can it be related to the ability to connect to a mobile phone when the app is not open?&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Thanks!&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>