{"id":29597411,"url":"https://github.com/twocity/linker","last_synced_at":"2025-07-20T10:06:30.540Z","repository":{"id":57736746,"uuid":"106270105","full_name":"twocity/linker","owner":"twocity","description":"A light weight URI routing framework for Android.","archived":false,"fork":false,"pushed_at":"2018-05-25T11:22:57.000Z","size":149,"stargazers_count":55,"open_issues_count":0,"forks_count":4,"subscribers_count":2,"default_branch":"develop","last_synced_at":"2023-07-05T04:13:32.059Z","etag":null,"topics":["android","annotation-processing","kotlin","kotlin-android","router"],"latest_commit_sha":null,"homepage":"","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/twocity.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-10-09T10:33:07.000Z","updated_at":"2021-10-20T04:27:23.000Z","dependencies_parsed_at":"2022-08-24T14:57:22.555Z","dependency_job_id":null,"html_url":"https://github.com/twocity/linker","commit_stats":null,"previous_names":[],"tags_count":0,"template":null,"template_full_name":null,"purl":"pkg:github/twocity/linker","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/twocity%2Flinker","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/twocity%2Flinker/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/twocity%2Flinker/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/twocity%2Flinker/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/twocity","download_url":"https://codeload.github.com/twocity/linker/tar.gz/refs/heads/develop","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/twocity%2Flinker/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":266103913,"owners_count":23876833,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["android","annotation-processing","kotlin","kotlin-android","router"],"created_at":"2025-07-20T10:01:31.794Z","updated_at":"2025-07-20T10:06:30.517Z","avatar_url":"https://github.com/twocity.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Linker [![Build Status](https://travis-ci.org/twocity/linker.svg?branch=master)](https://travis-ci.org/twocity/linker)\n\nLinker provides an annotation-based API to handle URI routing for Android. This library is written in kotlin, and the generated codes are also pure kotlin.\n\n## Dependencies\n\nAdd the following to your `build.gradle` file:\n\n```groovy\ndependencies {\n\tapi 'me.twocities:linker:0.0.5'\n\tkapt 'me.twocities:linker-compiler:0.0.5'\n}\n```\n\n## Usage\n\nThere are two parts of Linker: annotations and `LinkResolver`\n\n### Annotations\n\n__@Link for activity__\n\nUse annotation `@Link` indicate which URI was respect:\n\n```kotlin\n@Link(\"link://product/detail{id})\nclass ProductActivity: AppCompatActivity {\n}\n```\n\n__`@LinkPath` `@LinkQuery` for parameters__\n\n```kotlin\n@Link(\"link://product/detail/{id})\nclass ProductActivity: AppCompatActivity {\n  @LinkPath(\"id\") lateinit var productId: String\n  @LinkQuery(\"title\") lateinit var productTitle: String\n}\n```\n\nAfter annotation processing, an extension function `bindLinkParams()` of `ProductActivity` will be generated, you can use it to get values of `@LinkPath` `@LinkQuery` params:\n\n```kotlin\noverride fun onCreate(savedInstanceState: Bundle?) {\n  super.onCreate(savedInstanceState)\n  bindLinkParams()\n}\n```\n\n__`@LinkModule` for module__\n\n```kotlin\n// generate LinkerExampleLinkModule\n@LinkModule\nclass ExampleLinkModule\n```\n\nAfter annotation processing, a module class was generated, will contains informations of all defined `@Link`, `@LinkPath`, `@LinkQuery`. The generated class will be used to decided which uri will be routed.\n\n`@LinkModule` supports multi android's library module.\n\n__`@LinkResolverBuilder` for builder__\n\n```kotlin\n// generate LinkerExampleLinkResolverBuilder\n@LinkResolverBuilder(modules = arrayOf(ExampleLinkModule::class, LibraryLinkModule::class))\ninterface ExampleLinkResolverBuilder\n```\n\nThis will generate a LinkResolver's builder:\n\n```\nval resolver = LinkerExampleLinkResolverBuilder(context).build()\n```\n\n\n### LinkResolver\n\nThe definition of LinkResolver is much simpler:\n\n```kotlin\ninterface LinkResolver {\n  fun resolve(link: String): Result\n}\n```\nFunction `resolve` will parse the given link, and then return a `Result`, which has a nullable property of `Intent`, it will be null if no responding activities was found,\n\nRouting:\n\n```kotlin\nval result = resolver.resolve(\"link//product/detail/123\")\nif (result.success()) startActivity(result.intent)\n```\nThanks to kotlin, we can simplify this by writing extension function like this:\n\n```kotlin\nstartActivity(\"link://product/detail/123\")\n```\nsee [ObjectGraph](https://github.com/twocity/linker/blob/master/example/src/main/java/me/twocities/linker/example/ObjectGraph.kt) for more details.\n\n## Advance\n\nLinker also provide other mechanisms: `Interceptor`, `FallbackHandler`, which you can change the behavior of a link. You can add interceptors or set fallback handler by the generated builder class:\n\n```kotlin\n val resolver = LinkerBuilder(context)\n        .addInterceptor(HttpUrlInterceptor(context))\n        .setFallbackHandler(DefaultUrlHandler(context))\n        .setListener(ResolverListener())\n        .build()\n```\n\nthe Listener will be notified when an link was resolved.\n\n### Interceptors\n\nThe interceptor will give you an ability to change a link's intent, or put extra values to activity\n\n```kotlin\n// An interceptor handles how http(s) url was resolved\nclass HttpUrlInterceptor(private val context: Context) : Interceptor {\n  override fun intercept(link: String, metadata: LinkMetadata?): Intent? {\n    if (link.startsWith(\"http\") or link.startsWith(\"https\")) {\n      // since `LINK` will be passed to intent automatically, we can return the intent directly\n      return Intent(context, SimpleBrowserActivity::class.java)\n    }\n    return null\n  }\n}\n```\n\n### FallbackHandler\n\nIf there's no activities match with the given link, or no interceptors has intercepted, the fallback handler be called. The [FallbackHandler] gives you the ability to handle unknown link: start another activity or show an error page.\n\n## TODO\n\n+ [ ] Generate link's builder when compiling\n+ [ ] Support multi links for per activity\n+ [ ] More unit tests\n\n## Credit\n\n+ [DeepLinkDispatch](https://github.com/airbnb/DeepLinkDispatch)\n+ [ButterKnife](https://github.com/JakeWharton/butterknife)\n\n## License\n\nApache License, Version 2.0\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftwocity%2Flinker","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftwocity%2Flinker","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftwocity%2Flinker/lists"}