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:
- “category.Browsable” is to tell system this app has browsable content
- “action.view” is to tell system this activity can view data
- “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: