Enode Developers

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.

Sample

dependencies {
  ...
  implementation("io.enode:linkkit:1.0.0")
}

Copy linkTheming the SDK

You will need to ensure that your application has an MaterialComponents theme set, or another theme that is a child of MaterialComponents. For example, your AndroidManifest.xml could look like:

Sample

<application
        android:theme="@style/Theme.MaterialComponents.DayNight.NoActionBar"

You can also specify your own theme in which you can define the colors of LinkKit 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.

Sample

<item name="colorPrimary">#00000000/item>
<item name="colorOnPrimary">#FFFFFFFF</item>

Copy linkIntegrating the SDK

In your application section where you want to open LinkKit, import the SDK:

Sample

import io.enode.link.LinkKit

Ensure you have linkToken from the previous step and start the SDKs Activity with an Intent:

Sample

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.

If a user did not complete Link UI or dismisses the window, they will return to the previous Activity they were in.

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:

Sample

<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:

Sample

<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:

Sample

-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

Link SDK for iOS

Integrating with the Link SDK for iOS

React Native

Integrating with the Link SDKs in React Native

Was this article helpful?