需要通过蓝牙发送一个字符串
问题描述:
当我只发送一个字母或一个数字时,我的代码工作正常,但现在我试着编辑它使它发送两个值和一个“:”,但由于某种原因它不起作用。以下是我正在使用的代码:需要通过蓝牙发送一个字符串
@Override
public void onMove(int angle, int strength) {
mTextViewAngleLeft.setText(angle + "°");
mTextViewStrengthLeft.setText(strength + "%");
command = (angle + ":" + strength + "\n");
try {
outputStream.write(command.getBytes()); //transmits the value of command to the bluetooth module
} catch (IOException e) {
e.printStackTrace();
}
}
命令声明为String
。
答
转出它是一个硬件错误(蓝牙是不能正常工作)
试试这个代码https://stackoverflow.com/questions/22899475/android-sample-bluetooth-code-to-send- a-simple-string-via-bluetooth –
https://stackoverflow.com/a/22899728/3983054 –
1)为你的问题添加一些标点符号。 2)'它不工作'它究竟不工作? –