public void startService() {
   if (connectionType == Bluetooth) {
     if (mBluetoothConnectionService != null) {
       // Only if the state is STATE_NONE, do we know that we haven't started already
       if (mBluetoothConnectionService.getState() == BluetoothConnectionService.STATE_NONE) {
         // Start the BluetoothConnectionService
         mBluetoothConnectionService.start();
       }
     }
   } else if (connectionType == WiFi) {
     if (mWiFiConnectionService != null) {
       // Only if the state is STATE_NONE, do we know that we haven't started already
       if (mWiFiConnectionService.getState() == WiFiConnectionService.STATE_NONE) {
         // Start the BluetoothConnectionService
         mWiFiConnectionService.start();
       }
     }
   }
 }
  /**
   * Sends a message.
   *
   * @param message A string of text to send.
   */
  public synchronized void sendMessage(String message) {
    if (connectionType == Bluetooth) {
      // Check that we're actually connected before trying anything
      if (mBluetoothConnectionService.getState() != BluetoothConnectionService.STATE_CONNECTED) {
        Toast.makeText(this, 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 BluetoothConnectionService to write
        byte[] send = message.getBytes();
        mBluetoothConnectionService.write(send);

        // Reset out string buffer to zero and clear the edit text field
        mOutStringBuffer.setLength(0);
        // mOutEditText.setText(mOutStringBuffer);
      }
    } else if (connectionType == WiFi) {
      // Check that we're actually connected before trying anything
      if (mWiFiConnectionService.getState() != WiFiConnectionService.STATE_CONNECTED) {
        Toast.makeText(this, 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 WiFiConnectionService to write
        mWiFiConnectionService.sendMessage(message);

        // Reset out string buffer to zero and clear the edit text field
        mOutStringBuffer.setLength(0);
        // mOutEditText.setText(mOutStringBuffer);
      }
    }
  }