All Projects → tbruyelle → Rxpermissions

tbruyelle / Rxpermissions

Licence: apache-2.0
Android runtime permissions powered by RxJava2

Programming Languages

java
68154 projects - #9 most used programming language

Projects that are alternatives of or similar to Rxpermissions

Apiclient
A easy to use api client that combines the power of Retrofit, Realm, Gson, Rxjava and Retrolambda in a easy to use library for Java and Android
Stars: ✭ 100 (-99.03%)
Mutual labels:  rxjava
Ghost
微影,一款纯粹的在线视频App,基于Material Design + MVP + RxJava + Retrofit + Realm + Glide
Stars: ✭ 1,464 (-85.77%)
Mutual labels:  rxjava
Mvvm Architecture
The practice of MVVM + Jetpack architecture in Android.
Stars: ✭ 1,634 (-84.12%)
Mutual labels:  rxjava
Reactiveandroid
🚀 Simple and powerful ORM for Android
Stars: ✭ 102 (-99.01%)
Mutual labels:  rxjava
Rxdrive
RxJava wrapper for Google Drive Android API
Stars: ✭ 106 (-98.97%)
Mutual labels:  rxjava
Featureadapter
FeatureAdapter (FA) is an Android Library providing an optimized way to display complex screens on Android.
Stars: ✭ 112 (-98.91%)
Mutual labels:  rxjava
Qbox
🐈 RxJava+Retrofit+Okhttp+Glide + A life tool App, contains modules: news; jokes; constellation fortune; LED; weather; calendar; two-dimensional code, and more ... 小秋魔盒是一个生活工具 App,主要功能有:新闻资讯;微信精选美文;笑话趣图;星座运势;LED字幕;天气;日历;二维码;手电筒;老黄历。在开发中尽可能多的用了目前比较流行的框架和库。
Stars: ✭ 1,360 (-86.78%)
Mutual labels:  rxjava
Rxjavainaction
《RxJava2.x 实战》一书中包含的例子。
Stars: ✭ 116 (-98.87%)
Mutual labels:  rxjava
Rxjava
RxJava – Reactive Extensions for the JVM – a library for composing asynchronous and event-based programs using observable sequences for the Java VM.
Stars: ✭ 45,607 (+343.3%)
Mutual labels:  rxjava
Iron
Fast and easy to use NoSQL data storage with RxJava support
Stars: ✭ 112 (-98.91%)
Mutual labels:  rxjava
Cateye
高仿猫眼电影App
Stars: ✭ 102 (-99.01%)
Mutual labels:  rxjava
Mvvm Reddit
A companion project for our blog post on better Android software development using MVVM with RxJava.
Stars: ✭ 106 (-98.97%)
Mutual labels:  rxjava
Voice
Minimalistic audiobook player
Stars: ✭ 1,559 (-84.85%)
Mutual labels:  rxjava
Basemvp Master
一个基本的MVP应用框架(RxJava+Retrofit+Glide+IjkPlayer),封装比较完善,易于使用,帮助日常快速开发一个项目。
Stars: ✭ 101 (-99.02%)
Mutual labels:  rxjava
Unidirectional Architecture On Mobile
Dive into 📱 Unidirectional Architecture!
Stars: ✭ 115 (-98.88%)
Mutual labels:  rxjava
Mvpframes
整合大量主流开源项目并且可高度配置化的 Android MVP 快速集成框架,支持 AndroidX
Stars: ✭ 100 (-99.03%)
Mutual labels:  rxjava
Novate
A safety client by Https for android, (Android网络框架,基于Retrofit和RxJava打造的链式网络库, 支持okhttp的调用风格,又兼容Retrofit API,并支持rxJava链式操作)
Stars: ✭ 1,442 (-85.98%)
Mutual labels:  rxjava
Mvparms
⚔️ A common architecture for Android applications developing based on MVP, integrates many open source projects, to make your developing quicker and easier (一个整合了大量主流开源项目高度可配置化的 Android MVP 快速集成框架).
Stars: ✭ 10,146 (-1.38%)
Mutual labels:  rxjava
Rxlocationmanager
RxJava wrap around standard Android LocationManager without Google Play Services
Stars: ✭ 115 (-98.88%)
Mutual labels:  rxjava
Android Architecture
🌇该项目结合 MVP 与 Clean 架构思想,探索在 Android 项目上的最佳实践。
Stars: ✭ 112 (-98.91%)
Mutual labels:  rxjava

RxPermissions

BuildVersion Build Status

This library allows the usage of RxJava with the new Android M permission model.

Setup

To use this library your minSdkVersion must be >= 14.

allprojects {
    repositories {
        ...
        maven { url 'https://jitpack.io' }
    }
}

dependencies {
    implementation 'com.github.tbruyelle:rxpermissions:0.12'
}

Usage

Create a RxPermissions instance :

final RxPermissions rxPermissions = new RxPermissions(this); // where this is an Activity or Fragment instance

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.

Example : request the CAMERA permission (with Retrolambda for brevity, but not required)

// Must be done during an initialization phase like onCreate
rxPermissions
    .request(Manifest.permission.CAMERA)
    .subscribe(granted -> {
        if (granted) { // Always true pre-M
           // I can control the camera now
        } else {
           // Oups permission denied
        }
    });

If you need to trigger the permission request from a specific event, you need to setup your event as an observable inside an initialization phase.

You can use JakeWharton/RxBinding to turn your view to an observable (not included in the library).

Example :

// Must be done during an initialization phase like onCreate
RxView.clicks(findViewById(R.id.enableCamera))
    .compose(rxPermissions.ensure(Manifest.permission.CAMERA))
    .subscribe(granted -> {
        // R.id.enableCamera has been clicked
    });

If multiple permissions at the same time, the result is combined :

rxPermissions
    .request(Manifest.permission.CAMERA,
             Manifest.permission.READ_PHONE_STATE)
    .subscribe(granted -> {
        if (granted) {
           // All requested permissions are granted
        } else {
           // At least one permission is denied
        }
    });

You can also observe a detailed result with requestEach or ensureEach :

rxPermissions
    .requestEach(Manifest.permission.CAMERA,
             Manifest.permission.READ_PHONE_STATE)
    .subscribe(permission -> { // will emit 2 Permission objects
        if (permission.granted) {
           // `permission.name` is granted !
        } else if (permission.shouldShowRequestPermissionRationale) {
           // Denied permission without ask never again
        } else {
           // Denied permission with ask never again
           // Need to go to the settings
        }
    });

You can also get combined detailed result with requestEachCombined or ensureEachCombined :

rxPermissions
    .requestEachCombined(Manifest.permission.CAMERA,
             Manifest.permission.READ_PHONE_STATE)
    .subscribe(permission -> { // will emit 1 Permission object
        if (permission.granted) {
           // All permissions are granted !
        } else if (permission.shouldShowRequestPermissionRationale)
           // At least one denied permission without ask never again
        } else {
           // At least one denied permission with ask never again
           // Need to go to the settings
        }
    });

Look at the sample app for more.

Important read

As mentioned above, because your app may be restarted during the permission request, the request must be done during an initialization phase. This may be Activity.onCreate, or 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.

If not, and if your app is restarted during the permission request (because of a configuration change for instance), the user's answer will never be emitted to the subscriber.

You can find more details about that here.

Status

This library is still beta, so contributions are welcome. I'm currently using it in production since months without issue.

Benefits

  • Avoid worrying about the framework version. If the sdk is pre-M, the observer will automatically receive a granted result.

  • Prevents you to split your code between the permission request and the result handling. Currently without this library you have to request the permission in one place and handle the result in Activity.onRequestPermissionsResult().

  • All what RX provides about transformation, filter, chaining...

License

Copyright (C) 2015 Thomas Bruyelle

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

   http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].