QR Code Login for Android
To configure QR code login for an Android app, follow these steps.
The AndroidNativeKotlinTemplate
includes sample code for setting up QR code login. Find AndroidNativeKotlinTemplate
in Mobile SDK’s GitHub repository, github.com/forcedotcom/SalesforceMobileSDK-Templates.
To create an app by using the template, see Creating an Android Project with Forcedroid.
In AndroidNativeKotlinTemplate
, QR code login features are labeled by this comment: “Log in via Salesforce UI Bridge API generated QR codes.”
To enable QR code login features in AndroidNativeKotlinTemplate
, modify these files.
- To allow the app to receive QR code URLs scanned by other apps as deep linked intents, go to
AndroidManifest.xml
and uncomment the app’sMainActivity
intent-filter. - Customize the scheme attribute to match the app’s expected QR code login URLs.
If your app uses an Android link specification other than deep links, the configuration varies. See Android’s reference documentation, Handling Android App Links.
-
To provide a button for QR code login and implement the logic to scan a QR code, uncomment
QrCodeEnabledLoginActivity
, and then specify it as the activity class. Optionally, you can customize your own activity class as long as it can receive the URL and provide the UI Bridge API frontdoor URL and optional code verifier to Mobile SDK.
To customize the QR code login’s URL format, use the sample code provided in MainActivity.kt
.
When using a QR code login URL generated by the UI Bridge API, you can choose between Mobile SDK’s reference format or a custom format.
If you’re using our reference format, make sure to fill in these variables.
If you’re using a custom format, set isQrCodeLoginUsingReferenceUrlFormat
to false
, and then provide the URL handling logic in MainActivity.useQrCodeLogInUrl(url)
.
The onResume()
function calls setupQrCodeLogin()
to set up QR Code Login. When the intent has data for deep linked QR code login URLs, onResume()
calls useQrCodeLogInUrl()
. If you choose to implement a custom QR code login URL format, you can configure the app to receive the URLs in the onResume()
function and pass them to useQrCodeLogInUrl(). You can also customize the way useQrCodeLogInUrl() or another custom method retrieves the UI Bridge API’s frontdoor URL and optional code verifier.
For finer details on URL parsing, schemes, and structure, see the in-code comments in MainActivity.kt
.