SOLVED: GATT callback fails to register

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

时间: 2024-08-14 20:57:13

SOLVED: GATT callback fails to register的相关文章

android-BluetoothDevice

BluetoothDevice public final class BluetoothDevice  extends Object implements Parcelable java.lang.Object    ? android.bluetooth.BluetoothDevice Represents a remote Bluetooth device. A BluetoothDevice lets you create a connection with the respective

libev

Index NAME SYNOPSIS EXAMPLE PROGRAM ABOUT THIS DOCUMENT WHAT TO READ WHEN IN A HURRY ABOUT LIBEV FEATURES CONVENTIONS TIME REPRESENTATION ERROR HANDLING GLOBAL FUNCTIONS FUNCTIONS CONTROLLING EVENT LOOPS ANATOMY OF A WATCHER GENERIC WATCHER FUNCTIONS

laravel5.5用户认证源码分析

[toc] 1. 生成相关文件和配置 快速生成命令 php artisan make:auth 运行后,使用git查看有哪些文件变化 $ git status # On branch master # Changed but not updated: # (use "git add <file>..." to update what will be committed) # (use "git checkout -- <file>..." t

OpenGL多边形变换和裁剪

1 // Computer Graphics: HW2 2 // 3D Rendering pipeline: 3 // Space Transformation and Polygon clipping use Sutherland-Hodgman Algorithm 4 5 6 #include <iostream> 7 #include <string> 8 #include <cstdlib> 9 #include <cmath> 10 #inclu

Flux是一个Facebook团队的前端开发架构

Flux introduction 本文组成: React 官方文档翻译 相关实践心得. 内容上是Flux的介绍,例子将会在以后写出.一旦稍微多了解一点React,很难避免听到Flux这个名词.Flux是一个Facebook团队的前端开发架构.借助单向数据流等其它机制,使得React可以发挥了更加强大的功能.比起其它的框架,Flux更像是一种模式,我们可以投入较少的学习成本,快速上手Flux. Flux应用有三个主要的组成部分:调度者(dispatcher), 仓库(stores),视图(vie

[译文]casperjs 的API-casper模块

Casper class: 可以通过这个模块的create()方法来获取这个模块的一个实例,这是最容易的: var casper = require('casper').create(); 我们也可以通过实例化主方法的方式获得一个自身的实例: var casper = new require('casper').Casper(); 提示: 如果扩展casper类,后面的章节会讲到   不管是casper构造函数还是create()方法,都接受一个参数选项,这个标准的javascript对象一样.

re.match re.search re.findall区别

re正则表达式里面,常用的三种方法的区别. re.macth和search匹配得到的是match对象,findall得到的是一个列表. match从字符串开头开始匹配,search返回与正则表达式匹配的第一个子串,findall则返回所有匹配到的. 如果要匹配的东西是字符串中唯一的只有一个或者直线那个取一个,最好不用findall,findall能匹配所有必然会查找整个字符串,search找到一个就结束查找了.废话不多说,选取一个页面源码大的网页,例如获取新浪网页的编码. #coding=utf

OpenGL——3D Rendering Pipeline

1 // Computer Graphics: HW3 2 // 3D Transformation: 3 4 5 #include <iostream> 6 #include <string> 7 #include <cstdlib> 8 #include <cmath> 9 #include <cstdio> 10 #include <vector> 11 #include <gl/glut.h> 12 #includ

深入了解Android蓝牙Bluetooth——《进阶篇》

在 [深入了解Android蓝牙Bluetooth--<基础篇>](http://blog.csdn.net/androidstarjack/article/details/60468468)一篇中我们对蓝牙的各个版本的有了一个认识,蓝牙版本的历程及其优劣式介绍.那么接下来咱们就深入一点继续开车进入BLE的进及篇章. 蓝牙BLE4.x BLE分为三部分: Service Characteristic Descriptor 这三部分都用UUID作为唯一标识符.UUID为这种格式:0000ffe1