【发布时间】:2014-06-17 01:32:39
【问题描述】:
我能够发现,连接到蓝牙。
源代码---
通过蓝牙连接到远程设备:
//Get the device by its serial number
bdDevice = mBluetoothAdapter.getRemoteDevice(blackBox);
//for ble connection
bdDevice.connectGatt(getApplicationContext(), true, mGattCallback);
Gatt 状态回调:
private BluetoothGattCallback mGattCallback = new BluetoothGattCallback() {
@Override
public void onConnectionStateChange(BluetoothGatt gatt, int status, int newState) {
//Connection established
if (status == BluetoothGatt.GATT_SUCCESS
&& newState == BluetoothProfile.STATE_CONNECTED) {
//Discover services
gatt.discoverServices();
} else if (status == BluetoothGatt.GATT_SUCCESS
&& newState == BluetoothProfile.STATE_DISCONNECTED) {
//Handle a disconnect event
}
}
@Override
public void onServicesDiscovered(BluetoothGatt gatt, int status) {
//Now we can start reading/writing characteristics
}
};
现在我想向远程 BLE 设备发送命令,但不知道该怎么做。
一旦命令发送到 BLE 设备,BLE 设备将通过广播进行响应 我的应用程序可以接收的数据。
【问题讨论】:
-
我对 Android 不熟悉,对 iOS 更熟悉,我使用的是 BLE。但是你不能只写特征(如果允许的话)。所以你需要发现特征。逻辑是这样的:Peripheral -> Service(s) -> Characteristic(s)。
-
@Larme:这是否意味着苹果确实允许按照蓝牙规范中指定的 gatt 写入 - 特别是自定义 gatt 配置文件?您在没有 MFI 会员资格的情况下与 corebluetooth 进行 2 路通信成功了吗?
-
@andreas-manusm:是的,你可以。
-
我有类似的疑问,谁能看到链接并回复stackoverflow.com/questions/38935479/…
标签: android bluetooth-lowenergy android-bluetooth gatt