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.
app/src/main/AndroidManifest.xml
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’s MainActivity 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.
Note
1<!-- Uncomment when enabling login via UI Bridge API-generated QR codes -->23 <!-- This declares the app’s support for QR code login deep links. 4 The scheme can be customized by the app to match any scheme 5 used in the QR Code’s URL -->67 <!--<intent-filter>-->8 <!--<data android:scheme="mobileapp" />-->9 <!--<action android:name="android.intent.action.VIEW" />-->1011 <!--<category android:name="android.intent.category.BROWSABLE" />-->1213 <!--<category android:name="android.intent.category.DEFAULT" />-->14 <!--</intent-filter>-->
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.
1<!-- Use `android:name="com.salesforce.androidnativekotlintemplate.QrCodeEnabledLoginActivity"`2when enabling log in via Salesforce UI Bridge API generated QR codes -->3<!--<activity-->4<!--android:name="com.salesforce.androidsdk.ui.LoginActivity"-->5<!--android:exported="true"-->6<!--android:launchMode="singleTask"-->7<!--android:theme="@style/SalesforceSDK" />-->
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.
1internal var isQrCodeLoginUsingReferenceUrlFormat = true
If you’re using our reference format, make sure to fill in these variables.
1internal var qrCodeLoginUrlScheme = "YOUR_QR_CODE_LOGIN_URL_SCHEME"2internal var qrCodeLoginUrlHost = "YOUR_QR_CODE_LOGIN_URL_HOST"
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.
1override fun onResume() {2 ...34 // Check for and use the intent’s QR code login URL if applicable.5 // Uncomment when enabling login via Salesforce UI Bridge API generated QR codes6 //intent.data?.let { useQrCodeLogInUrl(it) }78 ...910 /* Uncomment when enabling log in via Salesforce UI Bridge API generated QR codes. */11 //setupQrCodeLogin()1213 ...1415 // Region QR Code Login Via Salesforce Identity API UI Bridge Private Implementation1617 /**18 * Sets up QR code login.19 */20 private fun setupQrCodeLogin() {21 // The scheme and host for the expected QR code log in URL format.22 check(qrCodeLoginUrlScheme != "your-qr-code-login-url-scheme") 23 { "Please add your login QR code URL's scheme." }2425 check(qrCodeLoginUrlHost != "your-qr-code-login-url-host") 26 { "Please add your login QR code URL's host." }2728 // The path, parameter names, and JSON keys for the expected QR code log in URL format.29 qrCodeLoginUrlPath = "your-qr-code-login-url-path"3031 qrCodeLoginUrlJsonParameterName = "your-qr-code-login-url-json-parameter-name"3233 qrCodeLoginUrlJsonFrontdoorBridgeUrlKey = 34 "your-qr-code-login-url-json-frontdoor-bridge-url-key"3536 qrCodeLoginUrlJsonPkceCodeVerifierKey = 37 "your-qr-code-login-url-json-pkce-code-verifier-key"3839 check(qrCodeLoginUrlPath != "your-qr-code-login-url-path") 40 { "Please add your login QR code URL's path." }4142 check(qrCodeLoginUrlJsonParameterName != "your-qr-code-login-url-json-parameter-name") 43 { "Please add your login QR code URL's UI Bridge API JSON query string parameter name." }4445 check(qrCodeLoginUrlJsonFrontdoorBridgeUrlKey != 46 "your-qr-code-login-url-json-frontdoor-bridge-url-key") 47 { "Please add your login QR code URL's UI Bridge API JSON frontdoor bridge URL key." }4849 check(qrCodeLoginUrlJsonPkceCodeVerifierKey != 50 "your-qr-code-login-url-json-pkce-code-verifier-key") 51 { "Please add your login QR code URL's UI Bridge API JSON PKCE code verifier key." }52 }5354 ...5556} 5758 // Endregion
We've Moved
Welcome to the new home of the Mobile SDK Developer Guide! For now, the Japanese guide can be found in PDF form.