Setting Custom Login Servers in Android Apps
For special cases—for example, if you’re a Salesforce partner using Trialforce—you can redirect your user’s login requests to a custom login URI.
In Android, login hosts are known as server connections. You can see the standard list of server connections in the res/xml/servers.xml
file of the SalesforceSDK
project. Mobile SDK uses this file to define production and sandbox servers.
For Android, the default login host can potentially be set through any of the following means.
-
MDM enforced
- At startup, your app’s MDM provider configures the login URI.
- The MDM policy can also hide the navigation bar and Settings icon to prevent users from changing the login host.
-
App configuration through the
servers.xml
fileYou can add your custom servers to the runtime list by creating your own
res/xml/servers.xml
file in your native Android project. The first server listed in yourservers.xml
file is used as the default login server at app startup. The root XML element forservers.xml
is<servers>
. This root can contain any number of<server>
entries. Each<server>
entry requires two attributes:name
(an arbitrary human-friendly label) andurl
(the web address of the login server, including the “https://” prefix).Here’s an example of a
servers.xml
file.To test XML changes in an Android emulator, we’ve found that it’s best to:
- Force stop the app if it’s already running in the emulator.
- Uninstall the app in the emulator.
- Do a full clean and rebuild.
- Run the app. :::
-
User configuration through the Add Connection button
Here’s how a user can configure a custom login server.
- Start the app without logging in.
- In the login screen, tap the Settings icon in the upper left corner.
- Tap Change Server.
- Tap Add Connection.
- To help identify this configuration in future visits, enter a name.
- Enter your custom login host’s URL. Be sure to include the
https://
prefix. For example, here’s how you enter a typical Experience Cloud site URL:
Mobile SDK enables this functionality by default. You can’t disable the Change Server or Add Connection option programmatically in Mobile SDK for Android.
- In Android, always include the “https://” prefix when specifying the login URL.
- At startup, MDM runtime configuration overrides compile-time settings.