Linkt
A lightweight and simple kotlin library for deep link handling on Android.
Setup
Configure root build.gradle
(jitpack.io):
allprojects {
repositories {
...
maven { url 'https://jitpack.io' }
}
}
Add Linkt
to your project build.gradle
:
dependencies {
implementation 'com.github.jeziellago:Linkt:TAG'
}
- Create your
DeepLinkModule
and register deep links:
Intent(context, MainActivity::class.java)
.apply { putExtras(bundle) }
}
}
}
“>
class MyDeepLinkModule : DeepLinkModule {
override fun load() {
deepLinkOf(
"linkt://sample",
"linkt://sample/{userId}/{userName}"
) { context, bundle ->
Intent(context, MainActivity::class.java)
.apply { putExtras(bundle) }
}
}
}
In multi-module projects you should have one or more DeepLinkModule`s.
- Register your modules into
Application#onCreate
, withDeepLinkLoader#setup
:
class MyApplication : Application() {
override fun onCreate() {
super.onCreate()
DeepLinkLoader.setup(MyDeepLinkModule())
}
}
- Create the
DeepLinkActivity
(or use yours if already exists), and callDeepLinkLoader#loadFrom
:
class DeepLinkActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
// resolve deeplink
DeepLinkLoader.loadFrom(this)
}
}
Don’t forget to configure AndroidManifest.xml
(required for Android deep links):
<div class="highlight highlight-text-xml position-relative" data-snippet-clipboard-copy-content="
“>
<activity android:name="org.linkt.DeepLinkActivity" android:theme="@android:style/Theme.NoDisplay"> <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="mycompany" /> intent-filter> activity>