Linkt

Project Url: jeziellago/Linkt
Introduction: A lightweight and simple Kotlin library for deep link handling on Android 🔗.
More: Author   ReportBugs   
Tags:

A lightweight and simple kotlin library for deep link handling on Android.

Setup

Add Linkt to your project build.gradle:

dependencies {
  implementation 'org.linkt:linkt:LATEST_VERSION'
}
  1. Create your DeepLinkModule and register deep links:

    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.

  1. Register your modules into Application#onCreate, with DeepLinkLoader#setup:
    class MyApplication : Application() {
     override fun onCreate() {
         super.onCreate()
         DeepLinkLoader.setup(MyDeepLinkModule())
     }
    }
    
  2. Create the DeepLinkActivity (or use yours if already exists), and call DeepLinkLoader#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):
    <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>
    
    In your activity, you can get path parameters and query values as String from intent.extras:

    Path parameters

  3. Template linkt://sample/{userId}/{userName}
  4. Received: linkt://sample/9999/Jose
    // get path parameters
    val userId = intent.extras.getString("userId")
    val userId = intent.extras.getString("userName")
    

    Query parameters

  5. Template: linkt://sample
  6. Received linkt://sample?subject=Linkt&name=Sample
    // get query parameters
    val subject = intent.extras.getString("subject")
    val name = intent.extras.getString("name")
    

    Path + query parameters

  7. Template linkt://sample/{userId}/{userName}
  8. Received linkt://sample/999/Jose?subject=Linkt&name=Sample
    // get path parameters
    val userId = intent.extras.getString("userId")
    val userId = intent.extras.getString("userName")
    // get query parameters
    val subject = intent.extras.getString("subject")
    val name = intent.extras.getString("name")
    

    Licence

    ``` Copyright (c) 2021 Jeziel Lago

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ```

Apps
About Me
GitHub: Trinea
Facebook: Dev Tools