好的,我有一个bluetooth.java类,希望它能发送我的字符串...但是每当我尝试发送命令时,我的错误消息只会显示nope。我是否遗漏了一些重要的东西?在那里我只有这两个功能..
void openBT() throws IOException {
UUID uuid = UUID.fromString("00001101-0000-1000-8000-00805f9b34fb");
try {
mmSocket = mmDevice.createRfcommSocketToServiceRecord(uuid);
} catch (IOException e) {
Toast.makeText(getApplicationContext(), "Unable to create socket", Toast.LENGTH_LONG).show();
}
try {
mmSocket.connect();
} catch (IOException e) {
Toast.makeText(getApplicationContext(), "Unable to connect to socket", Toast.LENGTH_LONG).show();
}
mmOutputStream = mmSocket.getOutputStream();
mmInputStream = mmSocket.getInputStream();
}
void sendData2() throws IOException {
if (BtCommand == "0"){
msg = "Fan2 Off";
}
if (BtCommand == "1"){
msg = "Fan2 On";
}
mmOutputStream.write(msg.getBytes());
}
这些是我设置的唯一内容
BluetoothSocket mmSocket;
BluetoothDevice mmDevice;
String BtCommand;
OutputStream mmOutputStream;
InputStream mmInputStream
我确定是 openBT 函数出了问题,我已经成功与设备配对。