Link SDK for Android
In this guide we will walk you through the steps to integrate the Link SDK for Android into your app.
Copy linkInclude the SDK
In your Android application’s build.gradle
, add the Link SDK as a dependency. Be sure to add the latest version and keep it up to date, which you can always see on Maven Central.
dependencies {
...
implementation("io.enode:linkkit:1.0.3")
}
Copy linkTheming the SDK
LinkKit can be themed by specifying a color for colorPrimary
and colorOnPrimary
. These two variables will be reflected in the color of LinkKit's toolbar and its contents respectively.
<item name="colorPrimary">#00000000/item>
<item name="colorOnPrimary">#FFFFFFFF</item>
These colors must be defined or LinkKit will fail to work. Some themes such as those that extend from MaterialComponents
set these colors by default.
Copy linkIntegrating the SDK
In your application section where you want to open LinkKit, import the SDK:
import io.enode.link.LinkKit
Ensure you have linkToken
from the previous step and start the SDKs Activity with an Intent:
private lateinit var resultLauncher: ActivityResultLauncher<Intent>
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
resultLauncher = registerForActivityResult(ActivityResultContracts.StartActivityForResult()) { result ->
if (result.resultCode == Activity.RESULT_OK) // Handle the result
}
}
// Launch LinkKit
val linkToken = "DxwPa..."
val intent = Intent(this, LinkKit::class.java)
intent.putExtra(LinkKit.INTENT_LINK_TOKEN, linkToken)
resultLauncher.launch(intent)
Once run, Link UI will open in your application and guide your user through the process of linking.
Upon success, users that click the "Complete" button will be redirected to the redirectUri
that was specified when you created the link session (if this URI was not a deeplink to your application, they will be redirected to the HTTP web page).
If a user did not complete Link UI or dismisses the window, they will return to the previous Activity they were in.
Copy linkError Codes
Here is a list of potential errors returned from LinkKit
Error Code | Description |
---|---|
missingLinkToken | No linkToken was passed into Link SDK. Check your implementation. |
malformedLinkToken | A malformed linkToken was passed into Link SDK. Check your implementation. |
cancelledByUser | The user manually exited out of the linking process. |
webViewNotInstalled | An Enode issue. Please contact support. |
sslError | An Enode issue. Please contact support. |
Copy linkTroubleshooting
Copy linkPermissions
The required Android permissions should automatically be included for your app via the LinkKit SDK. However, if they need to be incorporated into your development framework or environment manually, you should ensure the following are in your AndroidManifest.xml
:
<uses-permission
android:name="android.permission.BLUETOOTH"
android:maxSdkVersion="30" />
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
<uses-permission android:name="android.permission.BLUETOOTH_CONNECT" />
<uses-permission android:name="android.permission.BLUETOOTH_SCAN" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
Copy linkFailure to discover devices
If you are having trouble discovering devices via Bluetooth, first check to ensure you have the proper permissions above and that your users are accepting all of the permissions your app is requesting.
Occasionally other dependencies or imported libraries in your app may include permissions or flags that block the discovery of certain Bluetooth devices. You should ensure that your merged manifest doesn't include these sorts of conflicts. For example, it could be helpful to ensure in your permissions:
<uses-permission android:name="android.permission.BLUETOOTH_SCAN" tools:remove="android:usesPermissionFlags"/>
Copy linkRelease builds
If Link UI fails to load on release builds only, this can be a sign that there are issues be related to Android code minification or obfuscation. If this happens, you can prevent any optimization of LinkKit by adding this to your proguard-rules.pro
:
-keep class io.enode.link.** { *; }
Copy linkMinimum API Level
Android SDK version 1.0.0 requires Android API level (minSdkVersion
) 24 or higher in order to support newer features and increased stability. If you are upgrading from a previous version of the SDK, you may need to update your Android minimum SDK version.
Copy linkOther ways to integrate
Integrating with the Link SDK for iOS
Integrating with the Link SDKs in React Native