Pit Daddy's Android Ble problem log

Source: Internet
Author: User

The development of BLE (company project, anti-loss device) has been a period of time, because it is the first contact with BLE and the online data is not much, and the Android platform itself differences, encountered a lot of problems. For easy access in the future, make a note here.
1. ZTE Phone, after the Bluetooth manual disconnection, can not link the problem again. (there may be similar problems with other phones)
Workaround: Scan bluetoothadapter for a smooth resolution of this issue before connecting to GATT.

2.Gatt link is not stable (on some phones, this issue first excludes hardware issues.) This is only for the situation you encounter, perhaps a different solution, to be added)
Workaround: Due to the use of gattserver, this problem is caused by the lack of sequential restrictions between the start-up gattserver and the connection GATT. After repeated debugging, found that only need to create gattserver, after serviceadded, in the GATT link, at this time the GATT connection will be more stable.

3. Xiaomi phone encountered, after the GATT connection, manually call Gatt.disconnect and close. After the second link is automatically disconnected, the connection is re-bound again.
solution: Also inadvertently, saw an article, wrote Xiaomi Mobile phone in the GATT operation, it is best to do a sleep operation, it may be because the bottom of the millet to Bluetooth some things did not have time to release (guess). Therefore, in the GATT connection, before the gatt.discoverservices, plus sleep (500), found that after the disconnection in connection success rate greatly increased.

2014-11-14
4. Bluetooth off and on becomes unusually slow and even crashes
This issue may be associated with/gattserver for closed GATT connections when Bluetooth is turned off. My solution is to register the Bluetooth status of monitoring, when the Bluetooth status is found to Bluetoothadapter.state_turning_off, immediately release all the GATT connection, close the gattserver. By incomplete testing, Bluetooth has become much faster to close.

5. Onconnectionstatechange callback is not performed when Bluetooth is connected in bulk.
This problem is the pain of their own idle, in the test, with a lot of fake MAC address. So the result is conceivable, certainly is not even on the. But also found the problem, when ble to connect a nonexistent Mac, or not in the range of MAC address, found that sometimes do not make Onconnectionstatechange callback, feel very egg pain. Personally think it will be because, at the same time sending too many Connectgatt requests, resulting in the system of Bluetooth blocking or other problems.  No way, since the discovery of this problem, we have to solve. First, I added a scan when I was in the bulk of the Connectgatt connection, only to connect if the device I want to connect to is scanned. Then, I also made a connection to the GATT, do a synchronization (only one connection at a time, the previous connection does not end, unable to start a connection, but also for the connection without a callback to do a time-out processing, time-out to immediately release the current connection). It may not be intuitive to say so. But personally feel, in the operation of mobile phone Bluetooth, or do a good synchronization. Avoid the simultaneous occurrence of multiple GATT operations, but the mobile phone Bluetooth crash and other situations.


2014-11-266.GATT Link is not stable two
Recently, because of the serveice in the preservation of the GATT connection state, added a backstage lescan, suddenly found that the GATT connection has become unstable, do not know what the reason. Desperate circumstances, the background of the Lescan into another service, found that as if the GATT has become more stable, the current test has been connected for 40 minutes has not been disconnected.  I don't know what will happen next. Do not know whether it is because in the same thread in the GATT connection success, open Lescan will cause the connection is not stable, or the cause of the phone itself, I hope the expert advice.

2014-11-27
or the above problem, this morning, and retry the background scan and GATT connection, found that there are two times disconnected, eh .... Depressed, seeking expert advice.


All of the above-mentioned problems are the result of personal development experience, if there is any problem or lack of error, please correct your criticism.

Pit Daddy's Android Ble problem log

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.