{"id":13608228,"url":"https://github.com/alexstyl/warden","last_synced_at":"2025-04-08T20:00:01.234Z","repository":{"id":49397354,"uuid":"463311795","full_name":"alexstyl/warden","owner":"alexstyl","description":"Android permissions as suspend functions.","archived":false,"fork":false,"pushed_at":"2022-03-07T08:25:36.000Z","size":191,"stargazers_count":185,"open_issues_count":0,"forks_count":3,"subscribers_count":4,"default_branch":"main","last_synced_at":"2024-11-07T13:40:29.137Z","etag":null,"topics":["android","android-library","kotlin","permissions","suspend"],"latest_commit_sha":null,"homepage":"","language":"Kotlin","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/alexstyl.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2022-02-24T21:48:03.000Z","updated_at":"2024-11-04T16:54:47.000Z","dependencies_parsed_at":"2022-08-23T22:00:51.634Z","dependency_job_id":null,"html_url":"https://github.com/alexstyl/warden","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alexstyl%2Fwarden","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alexstyl%2Fwarden/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alexstyl%2Fwarden/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alexstyl%2Fwarden/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/alexstyl","download_url":"https://codeload.github.com/alexstyl/warden/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247918900,"owners_count":21018044,"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","android-library","kotlin","permissions","suspend"],"created_at":"2024-08-01T19:01:25.349Z","updated_at":"2025-04-08T20:00:01.215Z","avatar_url":"https://github.com/alexstyl.png","language":"Kotlin","funding_links":[],"categories":["Kotlin"],"sub_categories":[],"readme":"# Warden [![Featured on Android Weekly](https://androidweekly.net/issues/issue-508/badge)](https://androidweekly.net/issues/issue-508)\n\n![Android permissions as suspend functions](/assets/banner.png)\n\nPermission handling in Android can be complicated. It requires boilerplate code to setup the\npermission request, receive the result and then forward the result to the place of your codebase\nwhere the actual handling logic takes place.\n\nWarden removes all this boilerplate code and enables requesting permissions and receiving the result\nfrom any coroutine in your codebase (such as your ViewModels).\n\n## Quick Start\n\nInstall Warden via Gradle by adding the dependency in your `app/build.gradle` file:\n\n```gradle\nrepositories {\n  ...\n  mavenCentral()\n}\n\ndependencies {\n    implementation 'com.alexstyl:warden:1.0.0-alpha2'   \n}\n```\n\nThe following example showcases how to use Warden to request the `CALL_PHONE` permission.\n\n```kotlin\ncoroutineScope.launch {\n    val result = Warden.with(anyContext).requestPermission(Manifest.permission.CALL_PHONE)\n    when (result) {\n        is PermissionState.Denied -\u003e dialNumber(phoneNumber)\n        PermissionState.Granted -\u003e startCall(phoneNumber)\n    }\n}\n```\n\nAs soon as `requestPermission()` is called, Warden will ask Android for the requested permission and\nwill suspend the coroutine until the permission dialog has been dismissed.\n\nYou can use the `requestPermissions()` suspend function to request multiple permissions at once.\n\n\u003e The `Denied` state contains a `shouldShowRationale` property. When true, it is the right\n\u003e time to show an educational message towards why your app requires the said permission.\n\n## Limitations\n\n### Requesting permissions on the background\n\nThe way Warden works is via launching an activity which handles the permission requests for you. This is what enables Warden to request permission and receive the results from any part of your app. \n\nIf you need to request permissions while no activity is visible (such as from a service), you might be limited by the [restrictions on starting activities from the background](https://developer.android.com/guide/components/activities/background-starts).\n\n### Orientation changes and process death\n\nWarden assumes that the coroutine context you are requesting the permission from lives long enough until the permission dialog is dismissed.\nFor the cases the coroutine context doesn't exist, no one will be there to receive the result.\n\n## Sample app\n\nThe repository comes with a [sample app](/sample) for an example of usage.\n\n## Getting Help\n\nTo report a problem or request a feature, [open a new issue on Github][1].\n\n## License\n\nApache 2.0. See the [LICENSE](https://github.com/alexstyl/warden/blob/main/LICENSE) file for\ndetails.\n\n## Author\n\nMade by Alex Styl. [Follow @alexstyl](https://www.twitter.com/alexstyl) on Twitter for future\nupdates.\n\n[1]: https://github.com/alexstyl/warden/issues\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falexstyl%2Fwarden","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Falexstyl%2Fwarden","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falexstyl%2Fwarden/lists"}