android - 从 android 4.3 连接到 BLE113 时正在记录 "Client registered, waiting for callback"

标签 android bluetooth bluetooth-lowenergy samsung-mobile gatt

我正在尝试连接到 BlueGiga BLE113 设备和我的 Samsung Galaxy S4(Android 4.3)。我可以成功发现设备但无法连接和发现服务。 这是按下按钮连接后的日志。

12-30 16:38:34.012: D/BluetoothGatt(11280): registerApp()
12-30 16:38:34.012: D/BluetoothGatt(11280): registerApp() - UUID=5a5ac8ad-7583-457f-ba60-373c3beaf1b2
12-30 16:38:34.022: D/BluetoothGatt(11280): onClientRegistered() - status=0 clientIf=8
12-30 16:38:34.022: I/BluetoothGatt(11280): Client registered, waiting for callback
12-30 16:38:34.022: D/BluetoothGatt(11280): onClientConnectionState() - status=0 clientIf=8 device=FF:FF:FF:FF:FF:FF

传递给 connectGatt 方法的回调如下。

private BluetoothGattCallback mGattCallback = new BluetoothGattCallback() {
        @Override
        public void onConnectionStateChange(BluetoothGatt gatt, int status, int newState) {
            Log.i(TAG, "Trying to connect...");
            if (newState == BluetoothProfile.STATE_CONNECTED) {
                Log.i(TAG, "Connected to GATT server.");   
                gatt.discoverServices();

            } else if (newState == BluetoothProfile.STATE_DISCONNECTED) {
                Log.i(TAG, "Disconnected from GATT server.");
            }   
        }
};

最佳答案

这很可能是线程问题。我在三星 Galaxy S4 设备上遇到了与 BLE 非常相似的问题。看起来三星的 Android 实现处理 BLE 的方式与其他的不同(Nexus 7 设备运行良好)。尽管如此,您必须从 UI 线程显式运行 BLE connectGatt 方法。这是一个例子:

// Create handler for main thread where mContext is application context
mHandler = new Handler(mContext.getMainLooper());
...
// Connect to BLE device from mHandler
mHandler.post(new Runnable() {
    @Override
    public void run() {
        mBTGatt = mBTDevice.connectGatt(mContext, false, mGattCallback);
    }
});

关于android - 从 android 4.3 连接到 BLE113 时正在记录 "Client registered, waiting for callback",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20839018/

相关文章:

java - 解析带有地理标记数据的 RSS feed

android - 如何在Android手机上捕获蓝牙传出数据?

java - 在 Android 上使用蓝牙的服务发现失败异常

Android BLE扫描模式设置间隔

android - 低功耗蓝牙扫描失败

java - org.w3c.dom.Node.insertBefore : NullPointerException, 错误?

android - 在 ListView 后的屏幕底部添加按钮

ios - CBCentralManager 未开机

android - 如何在android中以表格格式显示数据?

ios - 在我的应用程序中未检测到新的 ibeacons