{"id":17688736,"url":"https://github.com/boybeak/easypermission","last_synced_at":"2025-05-13T00:47:57.736Z","repository":{"id":87642748,"uuid":"226340879","full_name":"boybeak/EasyPermission","owner":"boybeak","description":"Get permission dynamic","archived":false,"fork":false,"pushed_at":"2022-03-29T01:51:07.000Z","size":183,"stargazers_count":4,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-05-13T00:47:46.429Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"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/boybeak.png","metadata":{"files":{"readme":"README-CN.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-12-06T13:55:37.000Z","updated_at":"2022-03-29T01:16:39.000Z","dependencies_parsed_at":null,"dependency_job_id":"e78c5bdd-a1d4-488c-a933-7588794079a8","html_url":"https://github.com/boybeak/EasyPermission","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/boybeak%2FEasyPermission","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/boybeak%2FEasyPermission/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/boybeak%2FEasyPermission/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/boybeak%2FEasyPermission/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/boybeak","download_url":"https://codeload.github.com/boybeak/EasyPermission/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253850882,"owners_count":21973672,"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":[],"created_at":"2024-10-24T11:45:18.327Z","updated_at":"2025-05-13T00:47:57.713Z","avatar_url":"https://github.com/boybeak.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"# EasyPermission ![Download](https://img.shields.io/badge/easy--permission-2.1.0-blue)\n## 安装\n\n```groovy\n// root project build.gradle\nbuildscript {\n  allprojects {\n    repositories {\n        google()\n        jcenter()\n    }\n  }\n}\n```\n\n```groovy\nimplementation 'com.github.boybeak:easy-permission:${newest_version}'\n```\n\n## 使用\n\n**实例1**\n\n```kotlin\nEasyPermission.ask(\n\tManifest.permission.WRITE_EXTERNAL_STORAGE,\n  \tManifest.permission.CAMERA,\n  \tManifest.permission.ACCESS_FINE_LOCATION\n).go(this, REQUEST_CODE, object : Callback {\n    override fun onGranted(permissions: MutableList\u003cString\u003e, requestCode: Int) {\n      TODO(\"Do sth.\")\n    }\n\n    override fun onDenied(permission: String, requestCode: Int, neverAsk: Boolean) {\n      TODO(\"Permission denied.\")\n    }\n})\n```\n\n\n\n**实例2**\n\n如果你使用 `kotlin`来开发程序, 你可以使用这种方式.\n\n```kotlin\n//this may be Context or Fragment\nthis.withPermissions(\n  requestCode = 1,\n  permissions = *arrayOf(\n    Manifest.permission.WRITE_EXTERNAL_STORAGE,\n    Manifest.permission.CAMERA,\n    Manifest.permission.ACCESS_FINE_LOCATION\n  ),\n  onGranted = { permissions -\u003e\n\n              },\n  onDenied = { permission, requestCode, neverAsk -\u003e\n\n             }\n)\n```\n\n\n\n**实例3** - *推荐使用*\n\n这个实例基于 [`AspectJ`](https://github.com/HujiangTechnology/gradle_plugin_android_aspectjx) - 一个 java的**AOP** 库.\n\n\u003e 什么是 [AOP](https://en.wikipedia.org/wiki/Aspect-oriented_programming) ?\n\u003e\n\u003e 相关: [ASM](https://asm.ow2.io/), 直接在字节码中修改逻辑.\n\u003e\n\u003e 区别于: [APT](https://medium.com/@mauryahyd/what-is-android-apt-1fca2c4fc95a), 生成新的类.\n\n借助 `easy-permission-aspect` 库，通过该库中提供的 **@RequestPermissions** 和 **@OnPermissionDenied**来获取动态权限.\n\n```groovy\n// root project build.gradle\nbuildscript {\n  dependencies {\n    classpath 'com.hujiang.aspectjx:gradle-android-plugin-aspectjx:2.0.10'\n  }\n}\n```\n\n\n\nproguard-rules.pro\n\n```groovy\n-keepclassmembers class * {\n    @com.github.boybeak.easypermission.aspect.OnPermissionDenied \u003cmethods\u003e;\n    @com.github.boybeak.easypermission.aspect.RequestPermissions \u003cmethods\u003e;\n}\n```\n\n\n\n`com.github.boybeak:easy-permission-aspect:`[ ![Download](https://api.bintray.com/packages/boybeak/nulldreams/easy-permission-aspect/images/download.svg) ](https://bintray.com/boybeak/nulldreams/easy-permission-aspect/_latestVersion)\n\n```groovy\n// app or some other module's build.gradle\napply plugin: 'android-aspectjx'\n\n// ... some other stuff\n\ndependencies {\n  implementation fileTree(dir: 'libs', include: ['*.jar'])\n  implementation 'com.github.boybeak:easy-permission-aspect:${new_version}'\n  implementation 'org.aspectj:aspectjrt:1.9.5'\n}\n```\n\n\n\n- 在 **Context**, **Fragment** 或者 **View** 类中\n\n```kotlin\n@RequestPermissions(\n  permissions = [\n    Manifest.permission.ACCESS_FINE_LOCATION,\n    Manifest.permission.ACCESS_COARSE_LOCATION\n  ],\n  requestCode = REQUEST_CODE\n)\nfun getLocation() {\n  //TODO(\"GET LOCATION\")\n}\n\n@OnPermissionDenied\nfun onGetLocationDenied(permission: String, requestCode: Int, neverAsk: Boolean) {\n  //TODO(\"Permission denied\")\n}\n```\n\n- 如果你使用动态权限的方法没有在 **Context**, **Fragment** 或者 **View**类中, 你必须在方法的参数中，传入一个 **Context** 对象作为参数.\n\n```kotlin\n@RequestPermissions(\n  permissions = [\n    Manifest.permission.ACCESS_FINE_LOCATION,\n    Manifest.permission.ACCESS_COARSE_LOCATION\n  ],\n  requestCode = REQUEST_CODE\n)\nfun getLocation(context: Context) {\n  //TODO(\"GET LOCATION\")\n}\n```\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fboybeak%2Feasypermission","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fboybeak%2Feasypermission","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fboybeak%2Feasypermission/lists"}