Merge "WiFiDirectServiceDiscovery: Create a thread for sending message"

This commit is contained in:
Jimmy Chen
2018-12-27 02:14:10 +00:00
committed by Gerrit Code Review
2 changed files with 13 additions and 8 deletions

View File

@@ -65,12 +65,18 @@ public class ChatManager implements Runnable {
} }
} }
public void write(byte[] buffer) { public void write(String msg) {
byte[] buffer = msg.getBytes();
Thread thread = new Thread() {
public void run() {
try { try {
oStream.write(buffer); oStream.write(buffer);
} catch (IOException e) { } catch (IOException e) {
Log.e(TAG, "Exception during write", e); Log.e(TAG, "Exception during write", e);
} }
} }
};
thread.start();
}
} }

View File

@@ -43,8 +43,7 @@ public class WiFiChatFragment extends Fragment {
@Override @Override
public void onClick(View arg0) { public void onClick(View arg0) {
if (chatManager != null) { if (chatManager != null) {
chatManager.write(chatLine.getText().toString() chatManager.write(chatLine.getText().toString());
.getBytes());
pushMessage("Me: " + chatLine.getText().toString()); pushMessage("Me: " + chatLine.getText().toString());
chatLine.setText(""); chatLine.setText("");
chatLine.clearFocus(); chatLine.clearFocus();