有一个硬件,这个硬件可以接受键盘操作,然后把键盘操作转换为一个字节数组,通过蓝牙传输到我的手机上,我写了个小程序蓝牙连接他,尝试接受这个数组,有两个硬件设备测试都成功了,但是另一个死活没响应,已知对方设备也是android 4.0 ,而且会走到我代码中的连接成功部分。
BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter();
final BluetoothDevice device = adapter.getRemoteDevice("硬件设备的MAC地址 如 : 04:33:3A:12:15:5F");
BluetoothGattCallback bluetoothGattCallbackOne = new BluetoothGattCallback() {
@Override
public void onConnectionStateChange(BluetoothGatt gatt, int status, int newState) {
Log.i("gwh", status + "---" + newState);
if (status == BluetoothGatt.GATT_SUCCESS) {
if (newState == BluetoothProfile.STATE_CONNECTED) {
Log.i("gwh", "连接成功了.");
//搜索Service
gatt.discoverServices();
} else if (newState == BluetoothProfile.STATE_DISCONNECTED) {
Log.i("gwh", "连接失败了.");