public override void Run() { Log.Info(TAG, "BEGIN mConnectThread"); Name = "ConnectThread"; // Always cancel discovery because it will slow down a connection _service._adapter.CancelDiscovery(); // Make a connection to the BluetoothSocket try { // This is a blocking call and will only return on a // successful connection or an exception mmSocket.Connect(); } catch (Java.IO.IOException e) { _service.ConnectionFailed(); // Close the socket try { mmSocket.Close(); } catch (Java.IO.IOException e2) { Log.Error(TAG, "unable to close() socket during connection failure", e2); } // Start the service over to restart listening mode _service.Start(); return; } // Reset the ConnectThread because we're done lock (this) { _service.connectThread = null; } // Start the connected thread _service.Connected(mmSocket, mmDevice); }
protected override void OnResume() { base.OnResume(); // Performing this check in onResume() covers the case in which BT was // not enabled during onStart(), so we were paused to enable it... // onResume() will be called when ACTION_REQUEST_ENABLE activity returns. if (chatService != null) { // Only if the state is STATE_NONE, do we know that we haven't started already if (chatService.GetState() == BluetoothChatService.STATE_NONE) { // Start the Bluetooth chat services chatService.Start(); } } }