public override void OnResume() { base.OnResume(); if (chatService != null) { if (chatService.GetState() == BluetoothChatService.STATE_NONE) { chatService.Start(); } } }
public override void Run() { Log.Info(TAG, "BEGIN mConnectedThread"); byte[] buffer = new byte[1024]; int bytes; // Keep listening to the InputStream while connected while (service.GetState() == STATE_CONNECTED) { try { // Read from the InputStream /*bytes = inStream.Read(buffer, 0, buffer.Length); * * // Send the obtained bytes to the UI Activity * service.handler * .ObtainMessage(Constants.MESSAGE_READ, bytes, -1, buffer) * .SendToTarget();*/ bytes = inStream.Read(buffer); Message readMsg = service.handler.ObtainMessage(Constants.MESSAGE_READ, bytes, -1, buffer); readMsg.SendToTarget(); //buffer = null; } catch (Java.IO.IOException e) { Log.Error(TAG, "disconnected", e); service.ConnectionLost(); break; } } }
public override void Run() { Name = $"AcceptThread_{socketType}"; BluetoothSocket socket = null; while (service.GetState() != STATE_CONNECTED) { try { socket = serverSocket.Accept(); } catch (Java.IO.IOException e) { Log.Error(TAG, "accept() failed", e); break; } if (socket != null) { lock (this) { switch (service.GetState()) { case STATE_LISTEN: case STATE_CONNECTING: // Situation normal. Start the connected thread. service.Connected(socket, socket.RemoteDevice, socketType); break; case STATE_NONE: case STATE_CONNECTED: try { socket.Close(); } catch (Java.IO.IOException e) { Log.Error(TAG, "Could not close unwanted socket", e); } break; } } } } }