Android library for integrating with Mesh Connect.
Add dependency to your build.gradle
:
dependencies {
implementation 'com.meshconnect:link:$linkVersion'
}
The linkToken
should be obtained from
the /api/v1/linktoken
endpoint.
The request must be performed from the server side as it risks exposing your API secret.
You will get the response in the following format:
{
"content": {
"linkToken": "{linkToken}"
},
"status": "ok",
"message": ""
}
Each time you launch Link, you have to get a new linkToken
from your backend and build a new
LinkConfiguration
object:
val configuration = LinkConfiguration(
token = "linkToken"
)
Additional LinkConfiguration
object parameters:
-
accessTokens
to initialize crypto transfers flow at the 'Select asset step’ using previously obtained integrationauth_token
. It can be used if you have a validauth_token
and want to bypass authentication to jump right into a transfer. -
transferDestinationTokens
for crypto transfers flow. It is an alternative way of providing target addresses for crypto transfers by using previously obtained integrationauth_tokens
. -
disableDomainWhiteList
is a flag that allows to disable origin whitelisting. By default, it's enabled with the predefined domains.
The Link UI runs in a separate Activity within your app. To return the result you can use Activity Result APIs.
private val linkLauncher = registerForActivityResult(LaunchLink()) { result ->
when (result) {
is LinkSuccess -> /* handle success */
is LinkExit -> /* handle exit */
}
}
linkLauncher.launch(configuration)
At this point, Link UI will open and return the LinkSuccess
object if the user successfully
completes the flow.
When a user successfully links an account or completes the transfer, the LinkSuccess
object is
received. It contains a list of payloads that represent the linked items:
private fun onLinkSuccess(result: LinkSuccess) {
result.payloads.forEach { payload ->
when (payload) {
is AccessTokenPayload -> /* broker connected */
is DelayedAuthPayload -> /* delayed authentication */
is TransferFinishedSuccessPayload -> /* transfer succeed */
is TransferFinishedErrorPayload -> /* transfer failed */
}
}
}
When a user exits Link without successfully linking an account or an error occurs,
the LinkExit
object is received:
private fun onLinkExit(result: LinkExit) {
if (result.errorMessage != null) {
/* use error message */
}
}
A SharedFlow
emits payloads immediately:
lifecycleScope.launch {
LinkPayloads.collect { /* use payloads */ }
}
A SharedFlow
emits events that happen at certain points in the Link flow:
lifecycleScope.launch {
LinkEvents.collect { /* use event */ }
}
Standard deep links always create a new task or activity, unless you handle the back stack yourself. To resume the previous state, consider these steps:
- Define a custom URI scheme that is handled by a "No-op" activity.
- No-op activity checks if the app is already running. If so, it finishes itself.
AndroidManifest.xml:
<activity
android:name=".DeepLinkEntryActivity"
android:exported="true"
android:theme="@android:style/Theme.Translucent.NoTitleBar">
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="myapp" />
</intent-filter>
</activity>
DeepLinkEntryActivity.kt:
class DeepLinkEntryActivity : Activity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
// Check if app is already running
packageManager.getLaunchIntentForPackage(packageName)?.run {
addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP)
startActivity(this)
}
finish()
}
}
Test deeplink:
adb shell am start -a android.intent.action.VIEW -d "myapp://"
When triggered:
- If your app is in the background: it’s brought to the foreground.
- If it’s not running: the default launcher activity is opened.