The Trustly Lightbox SDK for Android allows you to quickly build a bank authorization workflow in your Android app. Integrate the Select Bank Widget or the Trustly Lightbox to retrieve bank authorization data that can be used with other Trustly APIs.
To use an example project for testing and learning, see the Android Example in GitHub.
If you need help with your integration, contact your Trustly representative or send your request to us.integrations@trustly.com.
v3 SDKs and above deprecated PayWithMyBank references. If your app previously used
v2 SDKs, you must change these references to Trustly when upgrading to a v3 or above SDK.
Android 15: Edge-to-edge display mode is the default behavior for Android 15 (API level 35) and later. If your app wasn’t designed for edge-to-edge display mode, critical elements of your app can be obscured. To ensure your app remains functional, you may need to use Window Insets to apply padding or margins to your layouts.
The following diagram illustrates how the Trustly SDK manages the secure transition between your application, the SDK, and the banking institution.
To add the Trustly SDK and the AndroidX Browser Library with Chrome Custom Tabs to your project, open your build.gradle file and add the following dependencies:
Sync your project to enable the dependency changes.
If your app does not have internet permissions enabled, open the AndroidManifest.xml file and add the INTERNET permission:
Define an App Link for your app if you have not defined one. Without it, customers are not automatically redirected to your app after they log in to their mobile banking app. See Set up App Links.
To ensure communications between the Trustly Lightbox SDK and the Trustly API are secure, use a requestSignature. You must generate a signature on your server using your access key and pass it to the Android app before rendering the Select Bank Widget or Trustly Lightbox.
Create a helper object in a new file named EstablishData.kt to hold your configuration:
When testing in the sandbox environment, set the env property to sandbox. You must remove the env property before publishing your production application.
To generate a requestSignature, see Generate request signatures. For a full list of parameters, see About OAuth Authentication.
Trustly recommends rendering the Select Bank Widget for an optimal customer experience.
In your activity’s layout XML (for example, activity_main.xml), add the TrustlyView:
In your activity’s onCreate method, initialize the widget and handle the bank selection event. Use onBankSelected to update your establishData with the customer’s choice:
Add a button to your activity’s layout XML (for example., activity_main.xml) to launch the payment flow:
Configure the button listener to launch a new activity. For example, LightboxActivity and pass the establishData:
In your LightboxActivity, call establish to open the Lightbox:
Optional. If your application doesn’t specify a screen orientation, add the android:configChanges attribute to your AndroidManifest.xml to handle rotation gracefully. For example:
For more information about handling configuration changes in Android apps, see Handle configuration changes.
The Trustly Lightbox provides two callback functions to handle transaction results:
onReturn: Called when the customer successfully authorizes the transaction.onCancel: Called if the customer exits the process or the authorization fails.Chain these callbacks to the establish method to handle the transaction result.
In the following example, a redirectToScreen helper function is used to prompt the customer when their transaction is successfully or unsuccessfully authorized:
Your application should retrieve data provided in the onReturn callback (such as the transaction ID) and pass it to your server for validation.
To support the transition from an external OAuth login (such as a bank app) back to the Lightbox, override the onRestart method in your LightboxActivity. This ensures the Lightbox resumes correctly after the user returns to your app.
Add an override to the LightboxActivity class to support the transition from the OAuth login authorization to the Lightbox launch. For example:
Configure Android App Links to ensure users return directly to your application after completing a transaction.