{"id":19372941,"url":"https://github.com/android-notes/onekeyperm","last_synced_at":"2025-04-23T16:33:38.626Z","repository":{"id":45722650,"uuid":"116790509","full_name":"android-notes/OneKeyPerm","owner":"android-notes","description":"一键申请Android权限，不依赖任何业务Activity。小巧、简约、强悍","archived":false,"fork":false,"pushed_at":"2020-08-10T14:26:21.000Z","size":155,"stargazers_count":61,"open_issues_count":0,"forks_count":15,"subscribers_count":1,"default_branch":"master","last_synced_at":"2023-03-06T14:53:27.996Z","etag":null,"topics":["android","permission","permission-android"],"latest_commit_sha":null,"homepage":"","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/android-notes.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":"2018-01-09T08:51:00.000Z","updated_at":"2023-02-24T12:07:57.000Z","dependencies_parsed_at":"2022-09-22T20:51:43.751Z","dependency_job_id":null,"html_url":"https://github.com/android-notes/OneKeyPerm","commit_stats":null,"previous_names":[],"tags_count":null,"template":null,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/android-notes%2FOneKeyPerm","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/android-notes%2FOneKeyPerm/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/android-notes%2FOneKeyPerm/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/android-notes%2FOneKeyPerm/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/android-notes","download_url":"https://codeload.github.com/android-notes/OneKeyPerm/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":223929845,"owners_count":17226972,"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","permission","permission-android"],"created_at":"2024-11-10T08:25:48.159Z","updated_at":"2024-11-10T08:25:48.612Z","avatar_url":"https://github.com/android-notes.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"# OneKeyPerm\n一键申请Android权限\n\n\n### OneKeyPerm接入说明\n\n\n \nOneKeyPerm不依赖任何业务Activity，支持多进程，只需一句静态代码就可以了\n\n例如\n\n```java\n申请权限被拒绝后 不会 自动开启设置页面让用户手动开启权限\n\nOneKeyPerm.request(application, Manifest.permission.CAMERA, \"您需要允许相机权限，否则无法使用扫码功能\", new OneKeyPerm.OnPermResultListener() {\n                    @Override\n                    public void onPermResult(String perm, boolean isGrant) {\n                        Toast.makeText(MainActivity.this, \"请求相机权限 \" + isGrant, Toast.LENGTH_SHORT).show();\n                    }\n                });\n```\n\n或者\n\n```java\n申请权限被拒绝后 会 自动开启设置页面让用户手动开启权限\n\nOneKeyPerm.request(application, Manifest.permission.CAMERA, \"您需要允许相机权限，否则无法使用扫码功能\", new OneKeyPerm.OnPermResultListener() {\n                    @Override\n                    public void onPermResult(String perm, boolean isGrant) {\n                        Toast.makeText(MainActivity.this, \"请求相机权限 \" + isGrant, Toast.LENGTH_SHORT).show();\n                    }\n                },true);\n```\n\n\n\n### 原理分析\n\n* 每次通过context启动透明Activity`（PermissionActivity）`请求权限\n\n* 当权限被拒绝后启动另一个透明Activity `(WatchAuthorizationActivity)`,在`WatchAuthorizationActivity`中再次启动应用详情设置Activity，然后在`WatchAuthorizationActivity`的`onActivityResult`方法中再次检查是否已经手动授权，并通过Binder（解决多进程问题）通知调用者\n\n\n备注：收回授权后Android会重启App\n\n\n\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fandroid-notes%2Fonekeyperm","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fandroid-notes%2Fonekeyperm","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fandroid-notes%2Fonekeyperm/lists"}