0

I'm running the BluetoothChat application with modifications made as follows :

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;
    }
};

The connection to the OBD device is perfect, but I do not receive any data from the device when i send "ATI" or "010C" etc.

I'm running the App in Android 4.4.2 (Kit Kat) and the App is based on the Sample BluetoothChat Application in Android 2.2

2 Answers2

0

I got it to work for me.

Instead of modifying TextView.OnEditorActionListener, modify sendMessage() in BluetoothChatFragment as follows:

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);
    }
}

The problem was that the send button doesn't go through the editor action listener.

Jon
  • 9,156
  • 9
  • 56
  • 73
0

I faced the same problem but your solution seems to only partially fix the problem. Sometimes it works and sometimes it doesn't. I have to re compile it until it works.

B.Lautus
  • 75
  • 7