{"id":3646,"url":"https://github.com/tbruyelle/RxPermissions","last_synced_at":"2025-08-11T04:30:52.057Z","repository":{"id":37818252,"uuid":"43370610","full_name":"tbruyelle/RxPermissions","owner":"tbruyelle","description":"Android runtime permissions powered by RxJava2","archived":true,"fork":false,"pushed_at":"2022-05-11T09:47:47.000Z","size":587,"stargazers_count":10482,"open_issues_count":101,"forks_count":1312,"subscribers_count":209,"default_branch":"master","last_synced_at":"2024-08-21T23:53:11.434Z","etag":null,"topics":["android","android-permissions","rxjava"],"latest_commit_sha":null,"homepage":"","language":"Java","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/tbruyelle.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":"2015-09-29T13:55:09.000Z","updated_at":"2024-08-21T08:42:14.000Z","dependencies_parsed_at":"2022-07-12T16:54:21.545Z","dependency_job_id":null,"html_url":"https://github.com/tbruyelle/RxPermissions","commit_stats":null,"previous_names":[],"tags_count":20,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tbruyelle%2FRxPermissions","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tbruyelle%2FRxPermissions/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tbruyelle%2FRxPermissions/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tbruyelle%2FRxPermissions/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/tbruyelle","download_url":"https://codeload.github.com/tbruyelle/RxPermissions/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":229493353,"owners_count":18081613,"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-permissions","rxjava"],"created_at":"2024-01-05T20:16:47.376Z","updated_at":"2024-12-13T04:30:38.752Z","avatar_url":"https://github.com/tbruyelle.png","language":"Java","funding_links":[],"categories":["Java","Libraries","Index","Android 应用","Library","Bindings","1. Important library"],"sub_categories":["Runtime Permissions","RxJava","网络服务_其他","一些原理分析的文章"],"readme":"# RxPermissions\n\n[![](https://jitpack.io/v/tbruyelle/RxPermissions.svg)](https://jitpack.io/#tbruyelle/RxPermissions) [![BuildVersion](https://buildstats.info/nuget/RxPermissions)](https://www.nuget.org/packages/RxPermissions/) [![Build Status](https://api.travis-ci.org/tbruyelle/RxPermissions.svg?branch=master)](https://travis-ci.org/tbruyelle/RxPermissions)\n\nThis library allows the usage of RxJava with the new Android M permission model.\n\n## Setup\n\nTo use this library your `minSdkVersion` must be \u003e= 14.\n\n```gradle\nallprojects {\n    repositories {\n        ...\n        maven { url 'https://jitpack.io' }\n    }\n}\n\ndependencies {\n    implementation 'com.github.tbruyelle:rxpermissions:0.12'\n}\n```\n\n## Usage\n\nCreate a `RxPermissions` instance :\n\n```java\nfinal RxPermissions rxPermissions = new RxPermissions(this); // where this is an Activity or Fragment instance\n```\n\n**NOTE:** `new RxPermissions(this)` the `this` parameter can be a FragmentActivity or a Fragment. If you are using `RxPermissions` inside of a fragment you should pass the fragment instance(`new RxPermissions(this)`) as constructor parameter rather than `new RxPermissions(fragment.getActivity())` or you could face a `java.lang.IllegalStateException: FragmentManager is already executing transactions`.  \n\nExample : request the CAMERA permission (with Retrolambda for brevity, but not required)\n\n```java\n// Must be done during an initialization phase like onCreate\nrxPermissions\n    .request(Manifest.permission.CAMERA)\n    .subscribe(granted -\u003e {\n        if (granted) { // Always true pre-M\n           // I can control the camera now\n        } else {\n           // Oups permission denied\n        }\n    });\n```\n\nIf you need to trigger the permission request from a specific event, you need to setup your event\nas an observable inside an initialization phase.\n\nYou can use [JakeWharton/RxBinding](https://github.com/JakeWharton/RxBinding) to turn your view to\nan observable (not included in the library).\n\nExample :\n\n```java\n// Must be done during an initialization phase like onCreate\nRxView.clicks(findViewById(R.id.enableCamera))\n    .compose(rxPermissions.ensure(Manifest.permission.CAMERA))\n    .subscribe(granted -\u003e {\n        // R.id.enableCamera has been clicked\n    });\n```\n\nIf multiple permissions at the same time, the result is combined :\n\n```java\nrxPermissions\n    .request(Manifest.permission.CAMERA,\n             Manifest.permission.READ_PHONE_STATE)\n    .subscribe(granted -\u003e {\n        if (granted) {\n           // All requested permissions are granted\n        } else {\n           // At least one permission is denied\n        }\n    });\n```\n\nYou can also observe a detailed result with `requestEach` or `ensureEach` :\n\n```java\nrxPermissions\n    .requestEach(Manifest.permission.CAMERA,\n             Manifest.permission.READ_PHONE_STATE)\n    .subscribe(permission -\u003e { // will emit 2 Permission objects\n        if (permission.granted) {\n           // `permission.name` is granted !\n        } else if (permission.shouldShowRequestPermissionRationale) {\n           // Denied permission without ask never again\n        } else {\n           // Denied permission with ask never again\n           // Need to go to the settings\n        }\n    });\n```\n\nYou can also get combined detailed result with `requestEachCombined` or `ensureEachCombined` :\n\n```java\nrxPermissions\n    .requestEachCombined(Manifest.permission.CAMERA,\n             Manifest.permission.READ_PHONE_STATE)\n    .subscribe(permission -\u003e { // will emit 1 Permission object\n        if (permission.granted) {\n           // All permissions are granted !\n        } else if (permission.shouldShowRequestPermissionRationale)\n           // At least one denied permission without ask never again\n        } else {\n           // At least one denied permission with ask never again\n           // Need to go to the settings\n        }\n    });\n```\n\nLook at the `sample` app for more.\n\n## Important read\n\n**As mentioned above, because your app may be restarted during the permission request, the request\nmust be done during an initialization phase**. This may be `Activity.onCreate`, or\n`View.onFinishInflate`, but not *pausing* methods like `onResume`, because you'll potentially create an infinite request loop, as your requesting activity is paused by the framework during the permission request.\n\nIf not, and if your app is restarted during the permission request (because of a configuration\nchange for instance), the user's answer will never be emitted to the subscriber.\n\nYou can find more details about that [here](https://github.com/tbruyelle/RxPermissions/issues/69).\n\n## Status\n\nThis library is still beta, so contributions are welcome.\nI'm currently using it in production since months without issue.\n\n## Benefits\n\n- Avoid worrying about the framework version. If the sdk is pre-M, the observer will automatically\nreceive a granted result.\n\n- Prevents you to split your code between the permission request and the result handling.\nCurrently without this library you have to request the permission in one place and handle the result\nin `Activity.onRequestPermissionsResult()`.\n\n- All what RX provides about transformation, filter, chaining...\n\n# License\n\n```\nCopyright (C) 2015 Thomas Bruyelle\n\nLicensed under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License.\nYou may obtain a copy of the License at\n\n   http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software\ndistributed under the License is distributed on an \"AS IS\" BASIS,\nWITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\nSee the License for the specific language governing permissions and\nlimitations under the License.\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftbruyelle%2FRxPermissions","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftbruyelle%2FRxPermissions","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftbruyelle%2FRxPermissions/lists"}