# Link SDK for Android In this guide we will walk you through the steps to integrate the Link SDK for Android into your app. ## Include 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](https://central.sonatype.com/artifact/io.enode/linkkit). ```json dependencies { ... implementation("io.enode:linkkit:1.0.6") } ``` ## Theming 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. ```xml #00000000 #FFFFFFFF ``` 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. ## Integrating the SDK Existing integrations: If your app already opens Link UI (e.g., in an in-app browser), follow these steps at the same place in your code. You should replace your old Link UI mechanism with a call to our SDK. In your application section where you want to open LinkKit, import the SDK: ```kotlin import io.enode.link.LinkKit ``` Ensure you have `linkToken` from the previous step and start the SDKs Activity with an Intent: ```kotlin private lateinit var resultLauncher: ActivityResultLauncher 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](https://developers.enode.com/docs/link-sdks/introduction#create-a-link-session) 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. ## Error 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 using Back Navigation/Gesture. | | USER_INTERACTION | The user manually exited the linking process by tapping the `x` button in the view. | | webViewNotInstalled | An Enode issue. Please contact support. | | sslError | An Enode issue. Please contact support. | ## Troubleshooting ### Permissions 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`: ```xml ``` ### Failure 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](https://developer.android.com/build/manage-manifests#merge-manifests) doesn't include these sorts of conflicts. For example, it could be helpful to ensure in your permissions: ```xml ``` ### Release 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`: ```java -keep class io.enode.link.** { *; } ``` ### Minimum 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. ## Other ways to integrate [Link SDK for iOS](https://developers.enode.com/docs/link-sdks/ios) [React Native](https://developers.enode.com/docs/link-sdks/react-native)