目前,我有一个要通过蓝牙连接的设备(用于Arduino的蓝牙模块)。但是每次我尝试连接时,都不会发生任何事情。有人可以告诉我我做错了吗?我的代码:
private static final UUID CONNUUID = UUID.fromString("0000110E-0000-1000-8000-00805F9B34FB");
public void connectDevice(BluetoothDevice bd){
try{
pairDia = ProgressDialog.show(this, "", "Connecting...", true, true);
BluetoothSocket bs = bd.createInsecureRfcommSocketToServiceRecord(CONNUUID);
}catch(Exception e){
e.printStackTrace();
this.finish();
}
}
}
最终,我想连接到该设备,然后为其创建一个套接字,然后可以对该字节进行读写。谢谢
你忘了打电话给connect()
您BluetoothSocket
:
// ...
BluetoothSocket bs = bd.createInsecureRfcommSocketToServiceRecord(CONNUUID);
bs.connect(); // note: blocking call
// ...
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句