• Stars
    star
    189
  • Rank 204,649 (Top 5 %)
  • Language
    Java
  • License
    Apache License 2.0
  • Created over 7 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Reactive permissions for Android

RxPermission

This library wraps the Android Runtime Permissions with RxJava 2. It's based on the RxPermissions library and was adjusted with simplicity in mind. Here are a few things that are different:

  • API is really small and focused
  • Uses a shadowing Activity to request the permission which allows you to use the library within Services, Broadcastreceiver etc.
  • Supports the 'Never ask again' case

Download

implementation 'com.vanniktech:rxpermission:0.10.0'
implementation 'com.vanniktech:rxpermission:0.11.0-SNAPSHOT'

Usage

The core functionality is provided via an interface:

interface RxPermission {
  /** Requests a single permission.  */
  @CheckReturnValue fun request(permission: String): Single<Permission>

  /** Requests multiple permissions.  */
  @CheckReturnValue fun requestEach(vararg permissions: String): Observable<Permission>

  /** Returns true when the given permission is granted.  */
  @CheckReturnValue fun isGranted(permission: String): Boolean

  /** Returns true when the given permission is revoked by a policy.  */
  @CheckReturnValue fun isRevokedByPolicy(permission: String): Boolean

  /** Returns tue when the given permission has been request at least once using either [request] or [requestEach].  */
  @CheckReturnValue fun hasRequested(permission: String): Boolean
}

And the Permission class:

public class Permission {
  /** The name of the permission. For instance android.permission.CAMERA */
  @NonNull public String name();

  /** The state of the permission. */
  @NonNull public State state();

  public enum State {
    /** Permission has been granted. */
    GRANTED,

    /** Permission has been denied. */
    DENIED,

    /**
     * Permission is denied.
     * Previously the requested permission was denied and never ask again was selected.
     * This means that the user hasn't seen the permission dialog.
     * The only way to let the user grant the permission is via the settings now.
     */
    DENIED_NOT_SHOWN,

    /** Permission has been revoked by a policy. */
    REVOKED_BY_POLICY
  }
}

Production

For your Android application you can get an instance of the interface via RealRxPermission.getInstance(application) and then simply use the above mentioned methods to your needs.

RealRxPermission.getInstance(application)
    .request(Manifest.permission.CAMERA)
    .subscribe();

Testing

In addition the library offers you a MockRxPermission that can be used for testing.

implementation 'com.vanniktech:rxpermission-testing:0.10.0'

The constructor takes a vararg of Permissions.

new MockRxPermission(Permission.denied(Manifest.permission.CAMERA))
    .request(Manifest.permission.CAMERA)
    .test()
    .assertResult(Permission.denied(Manifest.permission.CAMERA));

The Permission class provides you a few static factory methods:

/** This will create a granted Camera Permission instance. */
Permission.granted(Manifest.permission.CAMERA)

/** This will create a denied Camera Permission instance. */
Permission.denied(Manifest.permission.CAMERA)

/** This will create a denied not shown Camera Permission instance. */
Permission.deniedNotShown(Manifest.permission.CAMERA)

/** This will create a revoked by policy Camera Permission instance. */
Permission.revokedByPolicy(Manifest.permission.CAMERA)

Sample

Also checkout the sample app that shows you how to use the library.

License

Copyright (C) 2017 Vanniktech - Niklas Baudy

Licensed under the Apache License, Version 2.0

More Repositories

1

Emoji

A library to add Emoji support to your Android / iOS / JVM Application
Kotlin
1,523
star
2

gradle-dependency-graph-generator-plugin

Gradle plugin that generates dependency graphs from your project.
Kotlin
1,343
star
3

gradle-maven-publish-plugin

A Gradle plugin that publishes your Android and Kotlin libraries, including sources and javadoc, to Maven Central or any other Nexus instance.
Kotlin
1,252
star
4

OnActivityResult

OnActivityResult annotation compiler for Android
Java
461
star
5

RxRiddles

Riddling your way to master RxJava
Kotlin
455
star
6

gradle-android-junit-jacoco-plugin

Gradle plugin that generates JaCoCo reports from an Android Gradle Project
Groovy
397
star
7

lint-rules

A set of very opinionated lint rules.
Kotlin
353
star
8

gradle-code-quality-tools-plugin

Gradle plugin that generates ErrorProne, Findbugs, Checkstyle, PMD, CPD, Lint, Detekt & Ktlint Tasks for every subproject.
Kotlin
343
star
9

VNTNumberPickerPreference

NumberPicker Preference for Android
Java
174
star
10

gradle-android-apk-size-plugin

Gradle plugin that generates CSV files with apk size per output and variant of an apk
Groovy
84
star
11

gradle-android-javadoc-plugin

Gradle plugin that generates Java Documentation from an Android Gradle project.
Shell
80
star
12

VNTFontListPreference

ListPreference for Android which displays fonts
Java
77
star
13

kotlin-on-code-quality-tools

Demonstration of Code Quality Tools that are applicable with Kotlin
Kotlin
45
star
14

espresso-utils

Provides helper methods for asserting a few things that Espresso does not support out of the box.
Java
27
star
15

blurhash

BlurHash support for iOS, Android and JVM via Kotlin Multiplatform
Kotlin
19
star
16

TextBuilder

Provides a Class with a builder pattern for building beautiful text super easily. Internally it uses the Spannable API.
Java
17
star
17

SpeedReader

Cross-platform SpeedReader developed with Qt
C++
16
star
18

junit-rules

A set of handy junit rules.
Kotlin
15
star
19

RxBilling

Reactive wrapper around the Android Billing API
Kotlin
13
star
20

config-home

My home directory
Shell
12
star
21

multiplatform-locale

Type Safe Kotlin Multiplatform Locale implementation
Kotlin
10
star
22

SparseBuilders

Builders for SparseIntArray, SparseBooleanArray and SparseArray
Java
7
star
23

ui

Kotlin Multiplatform UI goodies
Kotlin
3
star
24

config-sublime

My Sublime 3 configuration
Python
1
star
25

playground

Empty project with basic dependencies for testing a few things out.
Ruby
1
star