Android BluetoothChat OBD-II设备

时间:2015-07-08 16:54:40

标签: android obd-ii

我正在运行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”等时,我没有从设备收到任何数据。

我在Android 4.4.2(Kit Kat)中运行应用程序,该应用程序基于Android 2.2中的示例BluetoothChat应用程序

2 个答案:

答案 0 :(得分:0)

我让它为我工作。

而不是修改TextView.OnEditorActionListener,修改sendMessage()中的BluetoothChatFragment,如下所示:

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

问题是发送按钮没有通过编辑器动作监听器。

答案 1 :(得分:0)

我遇到了同样的问题,但您的解决方案似乎只能部分解决问题。有时它有效,有时它不起作用。我必须重新编译它,直到它工作。