1 min read
Guides and customisations
How to set App links
Android App Links available on Android 6.0 (API level 23) and higher allows an app to designate itself as the default handler of a given type of link.
To add support for App links in your App:
- Add the links that your app can handle into your manifest.
- Create and store in the right location assetlinks.json file
LinksViewModel
will handle the resolution of your web link, thanks to a backend links resolver API call, into a DeepLink model.
How to obtain a DeepLink from a String
If your String contains App links or deep links, you need to:
- Call
LinksViewModel.processDeeplink
with your String:linksViewModel.processDeeplink(PoqResult.Success({YourString})) - Obtain your deep link from the LiveData
linksViewModel.deepLink
or an error fromlinksViewModel.error
.
If your String only contains deep links, you need to:
- Create a UriLink. You can use UriValidator to do it.
- Call
GetCategoryDeepLink
with your new UriLink.getDeepLinkFromUriLink(UriLink(uriValidator.createValidUri(deepLink), null))
How to navigate with a DeepLink
To navigate with a DeepLink you can use LinksNavigator
:
private val linksNavigator: LinksNavigator by inject { parametersOf(context.getFragmentActivity()) }...linksNavigator.navigate({yourDeepLink}})
How to add custom deep links
To add your own deep links, you need to:
- Create a custom deep link model with all your custom deep links.
sealed class CustomDeepLink {object CustomScreenDeepLink : CustomDeepLink()}
- Create a new implementation of
Mapper<DeepLink.ClientDeepLink?, UriLink>
, which transforms a String into your custom deep link or returns null if the Link SDK should handle that String.class CustomClientDeepLinkMapper (private val uriHelper: UriHelper) : Mapper<DeepLink.ClientDeepLink?, UriLink>private companion object {const val CUSTOM_DEEPLINK = "customdeeplink"}override fun map(origin: UriLink): DeepLink.ClientDeepLink? {return if (uriHelper.getHost(origin.uri) == CUSTOM_DEEPLINK) {DeepLink.ClientDeepLink(CustomDeepLink.DeepLink)} else {null}}} - Provide your new mapper via Koin using the name
clientDeepLinkMapperName
. - Create a new implementation of
ClientLinksNavigator
.class CustomClientLinksNavigator(private val activity: Activity) : ClientLinksNavigator {override fun navigate(deepLink: DeepLink.ClientDeepLink) { ... }} - Provide your new navigator via Koin.
factory<ClientLinksNavigator>(override = true) { (activity: Activity) -> CustomClientLinksNavigator(activity) }
How to add a new DeepLinkProvider
If you need to resolve deep links diferently, for example, for a new universal link provider, you need to:
- Create your new implementation of DeepLinkProvider
- In your
Application.onCreate
after calling super, call DeepLinkProviderManager.addProvider to include your new provider.