@SuppressWarnings("deprecation") // TODO: refactor to use DialogFrament
  @Override
  protected Dialog onCreateDialog(final int id, Bundle args) {
    Dialog dialog = null;
    switch (id) {
        /** Prompt to download Google Play Services from Google Play. */
      case DIALOG_ID_INSTALL_GOOGLE_PLAY_SERVICES:
        AlertDialog.Builder dlBuilder = new AlertDialog.Builder(this);
        dlBuilder.setMessage(Html.fromHtml(getString(R.string.update_google_play_services)));
        dlBuilder.setPositiveButton(
            R.string.update_button,
            new DialogInterface.OnClickListener() {
              @Override
              public void onClick(DialogInterface dialog, int whichButton) {
                Intent intent =
                    new Intent(
                        Intent.ACTION_VIEW,
                        Uri.parse(GOOGLE_PLAY_SERVICES_INSTALL_FROM_GOOGLE_PLAY));
                try {
                  startActivity(intent);
                } catch (ActivityNotFoundException e) { // if no Google Play app
                  startActivity(
                      new Intent(
                          Intent.ACTION_VIEW,
                          Uri.parse(GOOGLE_PLAY_SERVICES_INSTALL_FROM_WEB_BROWSER)));
                }
              }
            });
        dlBuilder.setNegativeButton(R.string.not_update_button, null);
        dialog = dlBuilder.create();
        break;

      case DIALOG_ID_SAVE_KEY:
        final SaveKeyDialogParams saveKeyDialogParams =
            (SaveKeyDialogParams) args.getSerializable(KEY_SAVE_KEY_DIALOG_PARAMS);
        dialog =
            new AlertDialog.Builder(this)
                .setTitle(R.string.save_key_message)
                // TODO: Add support for a nicely labeled issuer in this dialog
                .setMessage(
                    saveKeyDialogParams.index.toString()) // Use the fully qualified name here
                .setIcon(R.drawable.quantum_ic_report_problem_grey600_24)
                .setPositiveButton(
                    R.string.ok,
                    new DialogInterface.OnClickListener() {
                      @Override
                      public void onClick(DialogInterface dialog, int whichButton) {
                        saveSecretAndRefreshUserList(
                            saveKeyDialogParams.index,
                            saveKeyDialogParams.secret,
                            saveKeyDialogParams.type,
                            saveKeyDialogParams.counter);
                      }
                    })
                .setNegativeButton(R.string.cancel, null)
                .create();
        // Ensure that whenever this dialog is to be displayed via showDialog, it displays the
        // correct (latest) user/account name. If this dialog is not explicitly removed after it's
        // been dismissed, then next time showDialog is invoked, onCreateDialog will not be invoked
        // and the dialog will display the previous user/account name instead of the current one.
        dialog.setOnDismissListener(
            new DialogInterface.OnDismissListener() {
              @Override
              public void onDismiss(DialogInterface dialog) {
                removeDialog(id);
                onSaveKeyIntentConfirmationPromptDismissed();
              }
            });
        break;

      case DIALOG_ID_INVALID_QR_CODE:
        dialog =
            createOkAlertDialog(
                R.string.error_title,
                R.string.error_qr,
                R.drawable.quantum_ic_report_problem_grey600_24);
        markDialogAsResultOfSaveKeyIntent(dialog);
        break;

      case DIALOG_ID_INVALID_SECRET_IN_QR_CODE:
        dialog =
            createOkAlertDialog(
                R.string.error_title,
                R.string.error_uri,
                R.drawable.quantum_ic_report_problem_grey600_24);
        markDialogAsResultOfSaveKeyIntent(dialog);
        break;

      case DIALOG_ID_BARCODE_SCANNER_NOT_AVAILABLE:
        dialog = createOkAlertDialog(0, R.string.barcode_scanner_not_available, 0);
        break;

      case DIALOG_ID_LOW_STORAGE_FOR_BARCODE_SCANNER:
        dialog =
            createOkAlertDialog(
                R.string.low_storage_error_title, R.string.low_storage_error_detail, 0);
        break;

      case DIALOG_ID_CAMERA_NOT_AVAILABLE:
        dialog =
            new AlertDialog.Builder(this)
                .setTitle(R.string.camera_not_found_on_device_title)
                .setMessage(R.string.camera_not_found_on_device_detail)
                .setPositiveButton(R.string.close, null)
                .create();
        break;

        default:
          // do nothing
    }
    return dialog;
  }
Interprets the QR code that was scanned by the user. Decides whether to launch the key
provisioning sequence or the OTP seed setting sequence.

@param scanResult a URI holding the contents of the QR scan result
@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