TotpSecret

public interfaceTotpSecret


Represents a TOTP secret that is used for enrolling a TOTP second factor. Contains the shared secret key and other parameters to generate time-based one-time passwords. Implements methods to retrieve the shared secret key, generate a QR code URL, and open the QR code URL in an OTP authenticator app.

Summary

Public methods

abstract @NonNullString

Returns a QR code URL.

abstract @NonNullString

Returns a QR code URL.

abstract int

Returns the interval (in seconds) when the OTP codes should change.

abstract int

Returns the length of the OTP codes to be generated.

abstract long

Returns the timestamp (in seconds since epoch) by which enrollment should complete.

abstract @NonNullString

Returns the hashing algorithm used to generate time-based one-time passwords.

abstract @NonNullString

Returns the enrollment session.

abstract @NonNullString

Returns the shared secret key/seed used to generate time-based one-time passwords.

abstract void

Opens the specified QR Code URL in an OTP authenticator app on the device as a new Activity.

abstract void
openInOtpApp(
    @NonNullString qrCodeUrl,
    @NonNullString fallbackUrl,
    @NonNullActivity activity
)

Opens the specified QR Code URL in an OTP app on the device.

Public methods

generateQrCodeUrl

abstract @NonNullString generateQrCodeUrl()

Returns a QR code URL. For more details, seeKey-Uri-Format. You can display this URL to the end-user as a QR code to be scanned into an OTP authenticator app, like Google Authenticator. Alternatively, you can automatically load this URL into a TOTP authenticator app usingopenInOtpApp.

Returns
@NonNullString

A QR code URL String.

generateQrCodeUrl

abstract @NonNullString generateQrCodeUrl(@NonNullString accountName, @NonNullString issuer)

Returns a QR code URL. For more details, seeKey-Uri-Format. You can display this URL to the end-user as a QR code to be scanned into an OTP authenticator app, like Google Authenticator. Alternatively, you can automatically load this URL into a TOTP authenticator app usingopenInOtpApp.

Parameters
@NonNullString accountName

the name of the account/app along with a user identifier..

@NonNullString issuer

issuer of the TOTP (the app name).

Returns
@NonNullString

A QR code URL String.

getCodeIntervalSeconds

abstract int getCodeIntervalSeconds()

Returns the interval (in seconds) when the OTP codes should change.

Returns
int

The interval (in seconds) when the OTP codes should change.

getCodeLength

abstract int getCodeLength()

Returns the length of the OTP codes to be generated.

Returns
int

Length of the one-time passwords to be generated.

getEnrollmentCompletionDeadline

abstract long getEnrollmentCompletionDeadline()

Returns the timestamp (in seconds since epoch) by which enrollment should complete.

Returns
long

The timestamp (in seconds since epoch) by which enrollment should complete.

getHashAlgorithm

abstract @NonNullString getHashAlgorithm()

Returns the hashing algorithm used to generate time-based one-time passwords.

Returns
@NonNullString

Hashing algorithm used.

getSessionInfo

abstract @NonNullString getSessionInfo()

Returns the enrollment session.

getSharedSecretKey

abstract @NonNullString getSharedSecretKey()

Returns the shared secret key/seed used to generate time-based one-time passwords.

Returns
@NonNullString

Shared secret key for enrolling in TOTP MFA.

openInOtpApp

abstract void openInOtpApp(@NonNullString qrCodeUrl)

Opens the specified QR Code URL in an OTP authenticator app on the device as a new Activity. The shared secret key and account name will be populated in the OTP authenticator app. The URL uses theotpauth:// scheme and will be opened on an app that handles this scheme, if it exists on the device.

If a suitable OTP authenticator app was not found, this opens the Google Play Store instead, using the following URL:https://play.google.com/store/search?q=otpauth&c=apps.

Parameters
@NonNullString qrCodeUrl

the QR Code URL to open.

openInOtpApp

abstract void openInOtpApp(
    @NonNullString qrCodeUrl,
    @NonNullString fallbackUrl,
    @NonNullActivity activity
)

Opens the specified QR Code URL in an OTP app on the device. The shared secret key and account name will be populated in the OTP app. The URL uses theotpauth:// scheme and will be opened on an app that handles this scheme, if it exists on the device.

Parameters
@NonNullString qrCodeUrl

the QR Code URL to open.

@NonNullString fallbackUrl

the URL to open if a suitable OTP authenticator app was not found.

@NonNullActivity activity

a reference to the current activity, to open the OTP authenticator app on.

Except as otherwise noted, the content of this page is licensed under theCreative Commons Attribution 4.0 License, and code samples are licensed under theApache 2.0 License. For details, see theGoogle Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.

Last updated 2025-07-21 UTC.