@SuppressWarnings("deprecation") // TODO: refactor to use DialogFrament
  private void parseSecret(Uri uri, boolean confirmBeforeSave) {
    final String scheme = uri.getScheme().toLowerCase();
    final String path = uri.getPath();
    final String authority = uri.getAuthority();
    final String name;
    final String issuer;
    final String secret;
    final OtpType type;
    final Integer counter;

    if (!OTP_SCHEME.equals(scheme)) {
      Log.e(getString(R.string.app_name), LOCAL_TAG + ": Invalid or missing scheme in uri");
      showDialog(DIALOG_ID_INVALID_QR_CODE);
      return;
    }

    if (TOTP.equals(authority)) {
      type = OtpType.TOTP;
      counter = AccountDb.DEFAULT_HOTP_COUNTER; // only interesting for HOTP
    } else if (HOTP.equals(authority)) {
      type = OtpType.HOTP;
      String counterParameter = uri.getQueryParameter(COUNTER_PARAM);
      if (counterParameter != null) {
        try {
          counter = Integer.parseInt(counterParameter);
        } catch (NumberFormatException e) {
          Log.e(getString(R.string.app_name), LOCAL_TAG + ": Invalid counter in uri");
          showDialog(DIALOG_ID_INVALID_QR_CODE);
          return;
        }
      } else {
        counter = AccountDb.DEFAULT_HOTP_COUNTER;
      }
    } else {
      Log.e(getString(R.string.app_name), LOCAL_TAG + ": Invalid or missing authority in uri");
      showDialog(DIALOG_ID_INVALID_QR_CODE);
      return;
    }

    name = validateAndGetNameInPath(path);
    if (Strings.isNullOrEmpty(name)) {
      Log.e(getString(R.string.app_name), LOCAL_TAG + ": Missing user name in uri");
      showDialog(DIALOG_ID_INVALID_QR_CODE);
      return;
    }

    issuer = uri.getQueryParameter(ISSUER_PARAM);
    AccountIndex index = new AccountIndex(name, issuer);
    secret = uri.getQueryParameter(SECRET_PARAM);

    if (secret == null || secret.length() == 0) {
      Log.e(getString(R.string.app_name), LOCAL_TAG + ": Secret key not found in URI");
      showDialog(DIALOG_ID_INVALID_SECRET_IN_QR_CODE);
      return;
    }

    if (AccountDb.getSigningOracle(secret) == null) {
      Log.e(getString(R.string.app_name), LOCAL_TAG + ": Invalid secret key");
      showDialog(DIALOG_ID_INVALID_SECRET_IN_QR_CODE);
      return;
    }

    if (secret.equals(accountDb.getSecret(index))
        && counter.equals(accountDb.getCounter(index))
        && type == accountDb.getType(index)) {
      return; // nothing to update.
    }

    if (confirmBeforeSave) {
      Bundle dialogArgs = new Bundle();
      dialogArgs.putSerializable(
          KEY_SAVE_KEY_DIALOG_PARAMS, new SaveKeyDialogParams(index, secret, type, counter));
      showDialog(DIALOG_ID_SAVE_KEY, dialogArgs);
    } else {
      saveSecretAndRefreshUserList(index, secret, type, counter);
    }
  }
Parses a secret value from a URI. The format will be:

<p>otpauth://totp/user@example.com?secret=FFF...

<p>otpauth://hotp/user@example.com?secret=FFF...&counter=123

@param uri The URI containing the secret key
@param confirmBeforeSave a boolean to indicate if the user should be prompted for confirmation
    before updating the otp account information.
java/com/google/android/apps/authenticator/AuthenticatorActivity.java