2015-07-08 2 views
0

Я бегу приложение BluetoothChat с изменения, внесенные следующим образом:Android-BluetoothChat OBD-II нет ответа от устройства

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 подключение к устройству OBD идеально, но я не получаю y от устройства при отправке «ATI» или «010C» и т. д.

Я запускаю приложение в Android 4.4.2 (Kit Kat), и приложение основано на примере приложения BluetoothChat в Android 2.2

+0

Я думаю, что вы хотели назвать второй кусок кода «** BluetoothChatFragment **», а не «** BluetoothChatService **» – Jon

+0

Какое устройство obd-II вы используете? – Jon

ответ

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

Проблема заключалась в том, что кнопка отправки не проходит через слушателя редактор действий.

0

Я столкнулся с такой же проблемой, но ваше решение, похоже, лишь частично устраняет проблему. Иногда это работает, а иногда и нет. Я должен скомпилировать его, пока он не сработает.

Смежные вопросы