Skip to content

Commit

Permalink
Merge branch '2.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
Ralph Pina committed Apr 10, 2017
2 parents ade25b8 + c43454d commit 7ea69e0
Show file tree
Hide file tree
Showing 38 changed files with 4,113 additions and 3,334 deletions.
139 changes: 66 additions & 73 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,26 +1,40 @@
# Android Permissions Manager
Easily manage Android Marshmallow and up runtime permissions.
Easily manage Android Marshmallow and up runtime permissions. This library uses RXJava to skip all the painful parts of the `Activity`/`Fragment` lifecycle management.

### Checking Permissions

```java
PermissionsManager.get()
.requestCameraPermission()
.subscribe(new Action1<PermissionsResult>() {
@Override
public void call(PermissionsResult permissionsResult) {
if (permissionsResult.isGranted()) { // always true pre-M
// do whatever
}
if (permissionsResult.hasAskedForPermissions()) { // false if pre-M
// do whatever
}
}
});
```

This library is backwards compatible. In pre-Marshmallow devices permissions are returned as given. This is done using the Android Support library ```ActivityCompat``` and support ```Fragment``` methods for permissions. I've tried to make sure this library is well tested.

Javadocs can be found in the [docs](/docs) folder.

# Including Library
Simply imported it into your gradle project like so:

```groovy
compile 'net.ralphpina.permissionsmanager:permissions-manager:1.0.0'
```
JCenter is a pain to maintan, so I use [Jitpack.io](https://jitpack.io).

Or if you like using [Jitpack.io](https://jitpack.io) you can include it in your gradle file like so:
You can include it in your gradle file like so:

```groovy
repositories {
maven { url "https://jitpack.io" }
}
dependencies {
compile 'com.github.ralphpina:Android-Permissions-Manager:v1.0.0'
compile 'com.github.ralphpina:Android-Permissions-Manager:v2.0.0'
}
```

Expand All @@ -34,11 +48,10 @@ This library provides an interface to request ```PROTECTION_DANGEROUS``` Android
- MICROPHONE
- PHONE
- STORAGE
- BODY SENSORS
- SMS

See [Request Other Permissions](#request-other-permissions) to see how to use this library for permissions not listed above, namely:

- SENSORS
- SMS.
See [Request Other Permissions](#request-other-permissions) to see how to use this library to request various permissions in different groups.

The API allows you to check 3 things:
1. Whether the permission has been granted.
Expand Down Expand Up @@ -86,20 +99,7 @@ Make sure to include whatever permissions you will need in the ```AndroidManifes
...

</manifest>
```

### Checking ```onRequestPermissionsResult``` methods
Below are the main methods, however, you can also check out the Javadocs. Normally, after asking for a permission all you need to do is check in ```onResume``` whether the user has given you the permission. Otherwise, you can check using the following request codes in the ```Activity.onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults)``` or ```Fragment.onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults)``` methods of your view controller.

```java
PermissionsManager.REQUEST_CAMERA_PERMISSION;
PermissionsManager.REQUEST_LOCATION_PERMISSION;
PermissionsManager.REQUEST_AUDIO_RECORDING_PERMISSION;
PermissionsManager.REQUEST_CALENDAR_PERMISSION;
PermissionsManager.REQUEST_CONTACTS_PERMISSION;
PermissionsManager.REQUEST_STORAGE_PERMISSION;
PermissionsManager.REQUEST_CALL_PHONE_PERMISSION;
```
```

### Calendar

Expand All @@ -116,12 +116,6 @@ PermissionsManager.get()
.neverAskForCalendar(mActivity);
```

Request the permission. ```this``` can be an Activity of support Fragment.
```java
PermissionsManager.get()
.requestCalendarPermission(this);
```

### Camera

```java
Expand All @@ -137,12 +131,6 @@ PermissionsManager.get()
.neverAskForCamera(mActivity);
```

Request the permission. ```this``` can be an Activity of support Fragment.
```java
PermissionsManager.get()
.requestCameraPermission(this);
```

### Contacts

```java
Expand All @@ -158,12 +146,6 @@ PermissionsManager.get()
.neverAskForContacts(mActivity);
```

Request the permission. ```this``` can be an Activity of support Fragment.
```java
PermissionsManager.get()
.requestContactsPermission(this);
```

### Location

```java
Expand All @@ -179,12 +161,6 @@ PermissionsManager.get()
.neverAskForLocation(mActivity);
```

Request the permission. ```this``` can be an Activity of support Fragment.
```java
PermissionsManager.get()
.requestLocationPermission(this);
```

### Microphone

```java
Expand All @@ -200,12 +176,6 @@ PermissionsManager.get()
.neverAskForAudio(mActivity);
```

Request the permission. ```this``` can be an Activity of support Fragment.
```java
PermissionsManager.get()
.requestAudioRecordingPermission(this);
```

### Phone

```java
Expand All @@ -221,12 +191,6 @@ PermissionsManager.get()
.neverAskForCalling(mActivity);
```

Request the permission. ```this``` can be an Activity of support Fragment.
```java
PermissionsManager.get()
.requestCallingPermission(this);
```

### Storage

```java
Expand All @@ -242,10 +206,34 @@ PermissionsManager.get()
.neverAskForStorage(mActivity);
```

Request the permission. ```this``` can be an Activity of support Fragment.
### Body Sensors

```java
PermissionsManager.get()
.isBodySensorGranted()
```
```java
PermissionsManager.get()
.hasAskedForBodySensorPermission()
```
```java
PermissionsManager.get()
.neverAskForBodySensor(mActivity);
```

### SMS

```java
PermissionsManager.get()
.isSmsGranted()
```
```java
PermissionsManager.get()
.requestStoragePermission(this);
.hasAskedForSmsPermission()
```
```java
PermissionsManager.get()
.neverAskForSms(mActivity);
```

# Never Ask Again
Expand All @@ -258,18 +246,23 @@ PermissionsManager.get()

**If the user selected "Never ask again", then they give you permissions in the app settings page, and then remove them, this method will return true. Even though at that point you can ask for permissions. I have not been able to figure out a way around this.**

# Request Other Permissions
While there are methods to request some of the more common permissions, if the one you need is not there you can still use this library to request it. The example below tries to request body sensors:

```java
PermissionsManager.get()
.requestPermission(activity, REQUEST_CODE, BODY_SENSORS);
```
# Requesting Multiple Permissions
While there are methods to request some of the more common permissions, if you want to request multiple permissions at once:

To call into the should show request permission rationale methods you can also use this library:
```java
PermissionsManager.get()
.shouldShowRequestPermissionRationale(activity, BODY_SENSORS);
.requestPermissions(REQUEST_CAMERA_PERMISSION, REQUEST_LOCATION_PERMISSION)
.subscribe(new Action1<PermissionsResult>() {
@Override
public void call(PermissionsResult permissionsResult) {
if (permissionsResult.isGranted()) { // always true pre-M
// do whatever
}
if (permissionsResult.hasAskedForPermissions()) { // false if pre-M
// do whatever
}
}
});
```

# Contributing
Expand Down
29 changes: 16 additions & 13 deletions app/build.gradle
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
apply plugin: 'com.android.application'
apply plugin: 'com.android.databinding'

android {
compileSdkVersion 23
buildToolsVersion "23.0.2"
compileSdkVersion 25
buildToolsVersion "25.0.2"

dataBinding {
enabled = true
}

defaultConfig {
applicationId "net.ralphpina.permissionsmanager.sample"
minSdkVersion 16
targetSdkVersion 23
versionCode 1
versionName "1.0"
targetSdkVersion 25
versionCode 2
versionName "2.0"

testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
Expand All @@ -24,11 +27,11 @@ android {

dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'net.ralphpina.permissionsmanager:permissions-manager:1.0.0'
compile project(':permissions-manager')

// Support Libs
compile 'com.android.support:appcompat-v7:23.1.1'
compile 'com.android.support:design:23.1.1'
compile 'com.android.support:appcompat-v7:25.3.1'
compile 'com.android.support:design:25.3.1'

// Butterknife
compile 'com.jakewharton:butterknife:7.0.1'
Expand All @@ -37,8 +40,8 @@ dependencies {
testCompile 'junit:junit:4.12'
testCompile 'org.assertj:assertj-core:3.0.0'
// Force usage of support annotations in the test app, since it is internally used by the runner module.
androidTestCompile 'com.android.support:support-annotations:23.1.1'
androidTestCompile 'com.android.support.test:runner:0.4.1'
androidTestCompile 'com.android.support.test:rules:0.4.1'
androidTestCompile 'com.android.support.test.espresso:espresso-core:2.2.1'
androidTestCompile 'com.android.support:support-annotations:25.3.1'
androidTestCompile 'com.android.support.test:runner:0.5'
androidTestCompile 'com.android.support.test:rules:0.5'
androidTestCompile 'com.android.support.test.espresso:espresso-core:2.2.2'
}
Loading

0 comments on commit 7ea69e0

Please sign in to comment.