Android SDK - User Guide
Integration
The Android SDK can be added either via Maven package management or downloaded directly and added manually as an AAR bundle.
implementation 'money.link:linkaccount:3.+'
Setup
The Android SDK for security and FI support purposes uses Chrome Custom Tabs in order to surface the linking and payment session on a mobile device. Unlike Android Web Views, this requires configuration at the mobile application level in order to receive callbacks from the web application.
As such, the Android SDK requires setup of app links for receiving calls from the underlying web component. For this, the following steps are needed:
- Register the app link with your application.
- Create an assetlinks.json file in the project that owns the fallback website for the app link.
- Set up the LinkActivity to accept app links in the Activity Manifest.
Registering the App Link
Registering the App Link can be done through Android Studio. This link provides the details on using Android Studio to set up a new app link and how to populate assetlinks.json for both Debug and Release builds (including where in Google Play Console to get what should be in assetlinks.json for GPC-hosted release builds).
Setting up the Activity Manifest
An intent needs to be created in the Activity Manifest for ensuring that an activity exists in the application for handling the app link. The LinkActivity class is what would handle the app link and surface the result of the session in the session complete callback provided to LinkAccountDialog. For this, code similar to the below needs to be added to ActivityManifest.xml for your application.
1<activity
2 android:name="money.link.linkaccount.LinkActivity"
3 android:exported="true">
4 <intent-filter android:autoVerify="true">
5 <action android:name="android.intent.action.VIEW"/>
6 <category android:name="android.intent.category.DEFAULT"/>
7 <category android:name="android.intent.category.BROWSABLE"/>
8 <data android:scheme="https"
9 android:host="subdomain.domain.com"
10 android:path="/android-sdk/complete"/>
11 </intent-filter>
12</activity>
Additional information on integrating App Links with Android applications is here.
Usage
Create an instance of the LinkAccountDialog
class using the LinkAccountDialog.create
method passing along the sessionKey
, environment
, and redirectUrl
arguments. The Redirect URL should be the app link that was registered with your app. The SDK provides two environments, LinkEnvironment.SANDBOX
and LinkEnvironment.PRODUCTION
(default). To display the created LinkAccountDialog
instance the display
method needs to be called passing along a Context
object - off of which the activity is created for starting the Chrome Custom Tab to host the linking/payment session.
1import money.link.linkaccount.*
2import androidx.appcompat.app.AppCompatActivity
3
4class Activity : AppCompatActivity() {
5 ...
6
7 fun someButtonClicked(view: View) {
8 val dialog = LinkAccountDialog.create(sessionKey,
9 LinkEnvironment.PRODUCTION,
10 redirectUrl
11 )
12 dialog.display(this) { result ->
13 result.onSuccess { customerId ->
14 print("CustomerID is $customerId")
15 }
16 result.onFailure { error ->
17 print(error)
18 }
19 }
20 }
21}
The callback supplied to display
will be called once the linking and payment session completes for performing any activities to handle the linking and payout outcome.
If it is preferred to use the a view model to observe the outcome, the SessionResultViewModel
class is also available to populate with the SessionResult
on completion and observe for updates.
1import androidx.activity.viewModels
2import androidx.appcompat.app.AppCompatActivity
3
4class MainActivity : AppCompatActivity() {
5 private val viewModel: SessionResultViewModel by viewModels()
6 ...
7
8 fun someButtonClicked(view: View) {
9 dialog = LinkAccountDialog.create(it, environment, redirectUrl)
10 dialog.display(this, viewModel::setSessionResult)
11 }
12}
1import androidx.appcompat.app.AppCompatActivity
2import androidx activity.viewModels
3import money.link.linkaccount.*
4
5class MainActivity : AppCompatActivity() {
6
7 val viewModel: SessionResultViewModel by viewModels()
8
9 override fun onCreate(savedInstanceState: Bundle?) {
10 super.onCreate(savedInstanceState)
11 viewModel.linkAccountResult.observe(this) { result ->
12 result.onSuccess { customerId ->
13 print("Customer ID is $customerId")
14 }
15
16 result.onFailure { error ->
17 print(error)
18 }
19 }
20 }
21}