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的更多相关文章

  1. 【solved】must have one register DataBase alias named `default`

    beego在初始化MySQL数据库时报错处理 1.报错提示: ... [ORM]2019/10/11 08:42:52 register db Ping `default`, dial tcp 192 ...

  2. laravel5.5用户认证源码分析

    目录 1. 生成相关文件和配置 2. 分析路由文件 3. 以登陆开始为例,分析auth到底是怎么工作的 3.1 分析登录文件 3.2 分析门面Auth. 1. 生成相关文件和配置 快速生成命令 php ...

  3. 利用WCF双工模式实现即时通讯

    概述 WCF陆陆续续也用过多次,但每次都是浅尝辄止,以将够解决问题为王道,这几天稍闲,特寻了些资料看,昨晚尝试使用WCF的双工模式实现了一个简单的即时通讯程序,通过服务端转发实现客户端之间的通讯.这只 ...

  4. CREATE FILE encountered operating system error 5(Access is denied.)

    这篇博文主要演示"CREATE FILE encountered operating system error 5(Access is denied.)"错误如出现的原因(当然只是 ...

  5. Await, and UI, and deadlocks! Oh my!

    It’s been awesome seeing the level of interest developers have had for the Async CTP and how much us ...

  6. 彻底理解Toast原理和解决小米MIUI系统上没法弹Toast的问题

    1.Toast的基本使用 Toast在Android中属于系统消息通知,用来提示用户完成了什么操作.或者给用户一个必要的提醒.Toast的官方定义是这样的: A toast provides simp ...

  7. phalcon: queueing使用心得,需要安装相应的软体

    http://flyhighest.com/archives/50 原本没有用过phalcon的消息队列,本来以为很简单,结果搞了半天,把步骤记录一下. phalcon的官网上没有说需要安装beans ...

  8. Platform Invoke

    PInvoke 允许managed code 来调用在DLL中实施的unmanged function. Platform invoke relies on metadata to locate ex ...

  9. Android4.0窗口机制和创建过程分析

    一  前言 在谈到这个话题的时候,脑海里面千头万绪,因为它涉及到了方方面面的知识… 比如Activity管理,窗口添加,Token权限验证等等… 既然这么复杂,那么我们就复杂的问题简单化,可以分成下面 ...

随机推荐

  1. nodejs4-模块和包

    模块和包: 定义模块的方法跟sea.js类似,暴露一个接口也是使用exports. 调用一个接口就是使用require 注意:在引入模块的时候如果是同级目录需要加./,否则会报错   除了可以使用ex ...

  2. 十大Intellij IDEA快捷键(转)(2015年06月15日)

    注:本文转自:http://blog.csdn.net/dc_726/article/details/42784275 Intellij IDEA中有很多快捷键让人爱不释手,stackoverflow ...

  3. 关于arraylist.remove的一些小问题。

    public static void main(String[] args) { // TODO Auto-generated method stub ArrayList<Integer> ...

  4. Javascript delete 引用类型对象

    很少使用javascript的delete,最近因为一个小bug发现删除引用类型对象的时候有一点不同.如下面例子: var testVar = { a : { test : 1 } }, test1 ...

  5. Android—SDCard数据存取&Environment简介

    1:Environment简介: Environment是android.os包下的一个类,谷歌官方文旦的解释为:Provides access to environment variables(提供 ...

  6. 关于java中普通代码块、构造代码块与静态代码块

    1.普通代码块 public static void main(String[] args) { /*普通代码块: *直接定义在在方法或语句中出现”{普通代码的执行语句}“的就称为普通代码块. *普通 ...

  7. 北大ACM(POJ1006-Biorhythms)

    Question:http://poj.org/problem?id=1006 问题点:孙子定理 Memory: 248K Time: 0MS Language: C++ Result: Accept ...

  8. 20141017--循环语句for 穷举

    穷举:把所有的可能性都列举一遍 1.羽毛球怕15元一个,球3元一个,水2元一瓶,一共有200元,每种至少一个,列出所有可能: 2.   50元钱,有面值2元,3元,5元,不要求每种至少一张,有多少种组 ...

  9. linux 环境变量【转】

    1.引言 在 linux系统 下,如果你下载并安装了应用程序,很有可能在键入它的名称时出现" command not found "的提示内容.如果每次都到安装目标文件夹内,找到可 ...

  10. Ajax乱码问题

    Ajax中文乱码问题   1.js代码 var userName=$("#userName").val(); var url = "user/login.action?u ...