<?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 scanner app connects to device but my program doesn&amp;#39;t</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/34201/android-scanner-app-connects-to-device-but-my-program-doesn-t</link><description>Actually refers to the mobile version of nRF Connect but it&amp;#39;s not on the menu. 
 I have inherited a legacy Android app that connects to various BLE devices and reads data. Works OK except for one device (a weight scale). It simply won&amp;#39;t connect whether</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Wed, 16 May 2018 14:48:16 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/34201/android-scanner-app-connects-to-device-but-my-program-doesn-t" /><item><title>RE: Android scanner app connects to device but my program doesn't</title><link>https://devzone.nordicsemi.com/thread/132319?ContentTypeID=1</link><pubDate>Wed, 16 May 2018 14:48:16 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:f1bf88a6-8254-4057-ace4-7b1ef2f1abda</guid><dc:creator>Aleksander Nowakowski</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;So what I would recommend is:&lt;/p&gt;
&lt;p&gt;1. First always connect with autoConnect = false, as it&amp;#39;s much faster. Only when the device looses link and the app is in background you may use autoConnect = true so you don&amp;#39;t bother with timeouts, etc. But when user awaits actively, use false.&lt;/p&gt;
&lt;p&gt;2. Try connecting on UI thread. Some phones, for example from Samsung, like when you do BLE operations on the main thread.&lt;/p&gt;
&lt;p&gt;3. If other devices are working, I&amp;#39;d say it&amp;#39;s something with the weight scale. Did you try to sniff or get HCI snoop logs from the Android? Did you compare to other devices, is there any difference?&lt;/p&gt;
&lt;p&gt;4. Did you try another phone? It may be that your phone does not support some feature and after feature exchange it disconnects instead of ignoring it.&lt;/p&gt;
&lt;p&gt;The Android API on Android is so simple, that it&amp;#39;s really hard to do it wrong. Unfortunately, there is a lot of &amp;#39;workarounds&amp;#39; to make a connection more stable, like add delays, use UI thread, retry, clear device cache, etc, but none of then should be required.&lt;/p&gt;
&lt;p&gt;PS. I recommend using our BLE Library (&lt;a href="https://github.com/NordicSemiconductor/Android-BLE-Library/"&gt;https://github.com/NordicSemiconductor/Android-BLE-Library/)&lt;/a&gt; for keeping the connection, and in fact version 2 of it (develop branch). Version 2-alpha is highly not-stable but I&amp;#39;d like some feedback! However, RxAndroidBle should also&amp;nbsp; work properly.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Android scanner app connects to device but my program doesn't</title><link>https://devzone.nordicsemi.com/thread/131651?ContentTypeID=1</link><pubDate>Thu, 10 May 2018 21:22:53 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:03efd557-1013-4d60-b2e7-b23a46692813</guid><dc:creator>Rob Lewis</dc:creator><description>&lt;p&gt;Scan first, which finds the device, then&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;mBluetoothGatt = mBluetoothDevice.connectGatt(mContext, shouldAutoConnect, mGattCallback);&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;Have tried with shouldAutoConnect both true and false.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Log:&lt;/p&gt;
&lt;p&gt;05-07 08:57:09.986 15763-15826/com.calderadev.x200health D/BluetoothGatt: onClientConnectionState() - status=133 clientIf=6 device=88:1B:99:04:D7:40&lt;br /&gt;&lt;br /&gt;05-07 08:57:09.986 15763-15826/com.calderadev.x200health D/AbstractBleInteractor: [Callback] Connection state changed with status: 133 and new state: 0 (DISCONNECTED)&lt;br /&gt;05-07 08:57:09.986 15763-15826/com.calderadev.x200health W/AbstractBleInteractor: Error: (0x85)&lt;br /&gt;05-07 08:57:09.987 15763-15826/com.calderadev.x200health D/AbstractBleInteractor: Status&amp;#39;s value (decimal) = 133&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; onConnectionStateChange() - bluetoothGattOpenCount is at 1&lt;br /&gt;05-07 08:57:09.987 15763-15826/com.calderadev.x200health W/AbstractBleInteractor: BluetoothProfile.STATE_DISCONNECTED, closing connections and sending DeviceCommunicationsFailEvent&lt;br /&gt;05-07 08:57:09.987 15763-15826/com.calderadev.x200health D/AbstractBleInteractor: closeConnection()&lt;br /&gt;05-07 08:57:09.988 15763-15826/com.calderadev.x200health D/AbstractBleInteractor: gatt.closeConnection()&lt;br /&gt;05-07 08:57:09.988 15763-15826/com.calderadev.x200health D/BluetoothGatt: close()&lt;br /&gt;05-07 08:57:09.989 15763-15826/com.calderadev.x200health D/BluetoothGatt: unregisterApp() - mClientIf=6&lt;br /&gt;05-07 08:57:09.993 15763-15826/com.calderadev.x200health D/AbstractBleInteractor: closeConnection() - bluetoothGattOpenCount reducing to 0&lt;br /&gt;05-07 08:57:09.993 15763-15826/com.calderadev.x200health D/DefaultDeviceInteractor: onDeviceDisconnected&lt;br /&gt;05-07 08:57:09.995 15763-15763/com.calderadev.x200health D/PairDevicePresenter: onDeviceDisconnected&lt;br /&gt;05-07 08:57:10.000 15763-15763/com.calderadev.x200health D/MainActivity: onDeviceCommunicationsFail&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;As noted, it works with other devices.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>