@Override
  public void onCreate() {
    serviceCreatedAt = System.currentTimeMillis();
    log.debug(".onCreate()");

    super.onCreate();

    this.application = (WalletApplication) getApplication();
    this.wallet = application.getWallet();

    final BluetoothAdapter bluetoothAdapter = BluetoothAdapter.getDefaultAdapter();

    final PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
    wakeLock =
        pm.newWakeLock(
            PowerManager.PARTIAL_WAKE_LOCK, getPackageName() + " bluetooth transaction submission");
    wakeLock.acquire();

    registerReceiver(
        bluetoothStateChangeReceiver, new IntentFilter(BluetoothAdapter.ACTION_STATE_CHANGED));

    try {
      classicThread =
          new AcceptBluetoothThread.ClassicBluetoothThread(bluetoothAdapter) {
            @Override
            public boolean handleTx(final Transaction tx) {
              return AcceptBluetoothService.this.handleTx(tx);
            }
          };
      paymentProtocolThread =
          new AcceptBluetoothThread.PaymentProtocolThread(bluetoothAdapter) {
            @Override
            public boolean handleTx(final Transaction tx) {
              return AcceptBluetoothService.this.handleTx(tx);
            }
          };

      classicThread.start();
      paymentProtocolThread.start();
    } catch (final IOException x) {
      new Toast(this).longToast(R.string.error_bluetooth, x.getMessage());
      CrashReporter.saveBackgroundTrace(x, application.packageInfo());
    }
  }
  @Override
  public void onClick(final DialogInterface dialog, final int which) {
    final StringBuilder text = new StringBuilder();
    final ArrayList<Uri> attachments = new ArrayList<Uri>();
    final File cacheDir = context.getCacheDir();

    text.append(viewDescription.getText()).append('\n');

    try {
      text.append("\n\n\n=== application info ===\n\n");

      final CharSequence applicationInfo = collectApplicationInfo();

      text.append(applicationInfo);
    } catch (final IOException x) {
      text.append(x.toString()).append('\n');
    }

    try {
      final CharSequence stackTrace = collectStackTrace();

      if (stackTrace != null) {
        text.append("\n\n\n=== stack trace ===\n\n");
        text.append(stackTrace);
      }
    } catch (final IOException x) {
      text.append("\n\n\n=== stack trace ===\n\n");
      text.append(x.toString()).append('\n');
    }

    if (viewCollectDeviceInfo.isChecked()) {
      try {
        text.append("\n\n\n=== device info ===\n\n");

        final CharSequence deviceInfo = collectDeviceInfo();

        text.append(deviceInfo);
      } catch (final IOException x) {
        text.append(x.toString()).append('\n');
      }
    }

    if (viewCollectInstalledPackages.isChecked()) {
      try {
        text.append("\n\n\n=== installed packages ===\n\n");
        CrashReporter.appendInstalledPackages(text, context);
      } catch (final IOException x) {
        text.append(x.toString()).append('\n');
      }
    }

    if (viewCollectApplicationLog.isChecked()) {
      try {
        final File logDir = context.getDir("log", Context.MODE_PRIVATE);

        for (final File logFile : logDir.listFiles()) {
          final String logFileName = logFile.getName();
          final File file;
          if (logFileName.endsWith(".log.gz"))
            file =
                File.createTempFile(
                    logFileName.substring(0, logFileName.length() - 6), ".log.gz", cacheDir);
          else if (logFileName.endsWith(".log"))
            file =
                File.createTempFile(
                    logFileName.substring(0, logFileName.length() - 3), ".log", cacheDir);
          else continue;

          final InputStream is = new FileInputStream(logFile);
          final OutputStream os = new FileOutputStream(file);

          Io.copy(is, os);

          os.close();
          is.close();

          Io.chmod(file, 0777);

          attachments.add(Uri.fromFile(file));
        }
      } catch (final IOException x) {
        log.info("problem writing attachment", x);
      }
    }

    if (viewCollectWalletDump.isChecked()) {
      try {
        final CharSequence walletDump = collectWalletDump();

        if (walletDump != null) {
          final File file = File.createTempFile("wallet-dump.", ".txt", cacheDir);

          final Writer writer = new OutputStreamWriter(new FileOutputStream(file), Charsets.UTF_8);
          writer.write(walletDump.toString());
          writer.close();

          Io.chmod(file, 0777);

          attachments.add(Uri.fromFile(file));
        }
      } catch (final IOException x) {
        log.info("problem writing attachment", x);
      }
    }

    if (CrashReporter.hasSavedBackgroundTraces()) {
      text.append("\n\n\n=== saved exceptions ===\n\n");

      try {
        CrashReporter.appendSavedBackgroundTraces(text);
      } catch (final IOException x) {
        text.append(x.toString()).append('\n');
      }
    }

    text.append("\n\nPUT ADDITIONAL COMMENTS TO THE TOP. DOWN HERE NOBODY WILL NOTICE.");

    startSend(subject(), text, attachments);
  }