TheJadav

Deeplink in android with custom URI or callback url

This is commonly used technique for Oauth in many applications. This is also useful to forcing user to use application.

We are just covering how to handle deeplink in android application.

This is commonly used technique for Oauth in many applications. This is also useful to forcing user to use application.

We are just covering how to handle deeplink in android application.

Implement Custom Uri deeplink

Add following lines in Menifest.xml file

            <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="example"/>
            </intent-filter>

code explanation:

  1. “category.Browsable” is to tell system this app has browsable content
  2. “action.view” is to tell system this activity can view data
  3. “data” tag to describe scheme and host

Here my code opens app when user click on link like this : “example://myapp?show=true”, Above code is only checking scheme that is “example” and open app. But we can also specify host is my case it is “myapp”, which further defines specific host content only.
Now our app is opened, but sometime we might need some condition specific features after app opens from deep link. In my case I am showing dialog if show=true. To get data from uri we need to parse uri and its parameters.
Here I have showed how can we get uri in Activity file:

  
  override fun onResume() {
        super.onResume()
        val data  = intent.data
        val success = data?.getQueryParameter("show")
        
        /****/
    }
  
  

Check here I got uri in intent and also get query parameter from uri,
Note : always add new intent-filter when defining in Manifest.xml file.

Keep smiling & Learn something

Share this content:

Share:

More Posts

How does data persistence work in Android?

Data persistence in Android is the ability to save data to the device so that it can be accessed later, even if the app is closed or the device is restarted. There are several ways to achieve data persistence in Android

Fragments and Activities: Two Pillars of Android Development

Fragments and Activities are both important components of Android development. Fragments are a good choice for creating reusable and dynamic UIs, while Activities are a good choice for managing the lifecycle of an app’s UI and implementing core features.

Table of Contents

Send Us A Message