码迷,mamicode.com
首页 > 其他好文 > 详细

SOLVED: GATT callback fails to register

时间:2014-06-17 15:21:50      阅读:240      评论:0      收藏:0      [点我收藏+]

标签:android   class   code   http   tar   ext   

I finally figured this problem out. The device I am using is a Samsung Galaxy S4 and the actual problem (thanks Wibble for guidance in your answer, but you are slightly off in your conclusion) appears to be a threading issue.

In Wibble‘s answer, he stated that adding a button to connect fixed his issue. I started wondering why that matters, and I also can connect and disconnect fine during an entire session without a GUI button using background worker threads. As soon as I force close my application, restart it, and try to connect, I start getting the error "Failed to register callback." and nothing works any more. I almost pulled my hair out over this one :)

See my post in Samsung‘s forums for more detail on my exact issues.

Solution: To get around this issue, just make sure you run any BLE interaction code (device#connectGatt, connect, disconnect, etc) code in the UIThread (with a handler, local service, or Activity#runOnUiThread). Follow this rule of thumb and you will hopefully avoid this dreadful problem.

Deep in our library, I only had access to the application context. You can create a handler from a context that will post to the main thread by using new Handler(ctx.getMainLooper());

If you face other connection problems, deploy the sample app in samples\android-18\legacy\BluetoothLeGatt and see if that application works. That was kind of my baseline for realizing BLE does actually work with my peripheral, and gave me hope that if I dug enough in our library I would eventually find the answer.

EDIT: I did not see this ‘Failed to register callback‘ issue on the Nexus 4, Nexus 5, or Nexus 7 2013 when using background threads to perform BLE operations. It may just be an issue in Samsungs 4.3 implementation.

 

http://stackoverflow.com/questions/20069507/solved-gatt-callback-fails-to-register

 

 

SOLVED: GATT callback fails to register,布布扣,bubuko.com

SOLVED: GATT callback fails to register

标签:android   class   code   http   tar   ext   

原文地址:http://www.cnblogs.com/savagemorgan/p/3792465.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!