我运行BluetoothChat应用程序时所做的修改如下:
BluetoothChatService
// Unique UUID for this application
private static final UUID MY_UUID = UUID.fromString("00001101-0000-1000-8000-00805F9B34FB");BluetoothChatService
// The action listener for the EditText widget, to listen for the return key
private TextView.OnEditorActionListener mWriteListener =
new TextView.OnEditorActionListener() {
public boolean onEditorAction(TextView view, int actionId, KeyEvent event) {
// If the action is a key-up event on the return key, send the message
if (actionId == EditorInfo.IME_NULL && event.getAction() == KeyEvent.ACTION_UP) {
String message = view.getText().toString();
sendMessage(message+ "\r");//My CHANGE
}
if(D) Log.i(TAG, "END onEditorAction");
return true;
}
};与OBD设备的连接是完美的,但当我发送"ATI“或"010C”等时,我不会从该设备接收任何数据。
我在Android4.4.2( Kat)中运行该应用程序,该应用程序基于Android2.2中的示例BluetoothChat应用程序
发布于 2015-07-10 17:58:20
我让它为我工作。
与其修改TextView.OnEditorActionListener,不如在BluetoothChatFragment中修改sendMessage(),如下所示:
private void sendMessage(String message) {
message = message + '\r'; //MY CHANGE
// Check that we're actually connected before trying anything
if (mChatService.getState() != BluetoothChatService.STATE_CONNECTED) {
Toast.makeText(getActivity(), R.string.not_connected, Toast.LENGTH_SHORT).show();
return;
}
// Check that there's actually something to send
if (message.length() > 0) {
// Get the message bytes and tell the BluetoothChatService to write
byte[] send = message.getBytes();
mChatService.write(send);
// Reset out string buffer to zero and clear the edit text field
mOutStringBuffer.setLength(0);
mOutEditText.setText(mOutStringBuffer);
}
}问题是发送按钮没有通过编辑器操作侦听器。
发布于 2016-12-21 08:35:31
我也面临着同样的问题,但你的解决方案似乎只是部分地解决了问题。有时起作用,有时不起作用。我必须重新编译它,直到它工作为止。
https://stackoverflow.com/questions/31298958
复制相似问题