为了以编程方式将数据发送到另一台蓝牙设备,我是 使用蓝牙套接字代码。我什么时候打电话 bluetoothSocket.connect();它给连接拒绝或连接 对等异常。 我还有一个混乱,我必须在其中使用UUI或从我可以获得它.Below是代码片段。
public void openBT() {
UUID uuid = UUID.fromString("00001101-0000-1000-8000-00805f9b34fb"); // Standard
// SerialPortService
try {
mmSocket = mmDevice.createInsecureRfcommSocketToServiceRecord(uuid);
Method m = mmDevice.getClass().getMethod("createInsecureRfcommSocket", new Class[] {int.class});
mmSocket = (BluetoothSocket) m.invoke(mmDevice, 3);
mBluetoothAdapter.cancelDiscovery();
mmSocket.connect();
/*mmSocket = mmDevice.createRfcommSocketToServiceRecord(uuid);
mmSocket.connect();*/
mmOutputStream = mmSocket.getOutputStream();
mmInputStream = mmSocket.getInputStream();
beginListenForData();
myLabel.setText("Bluetooth Opened");
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
帮助赞赏.. !!