从android 4.3连接到BLE113时,正在记录;客户端已注册,正在等待回调;

从android 4.3连接到BLE113时,正在记录;客户端已注册,正在等待回调;,android,bluetooth,bluetooth-lowenergy,samsung-mobile,gatt,Android,Bluetooth,Bluetooth Lowenergy,Samsung Mobile,Gatt,我正在尝试连接BlueGiga BLE113设备和我的三星Galaxy S4(安卓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:

我正在尝试连接BlueGiga BLE113设备和我的三星Galaxy S4(安卓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非常类似的问题。看来三星的安卓操作系统处理BLE的方式与其他设备不同(Nexus7设备运行良好)。尽管如此,您必须从UI线程显式运行您的可连接GATT方法。以下是一个例子:

// 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和BLE示例,我已经发布了一个关于Github上的空中编程(即将完成)的示例: