All Projects → florent37 → Runtimepermission

florent37 / Runtimepermission

Licence: apache-2.0
Simpliest way to ask runtime permissions on Android, no need to extend class or override permissionResult method, choose your way : Kotlin / Coroutines / RxJava / Java7 / Java8

Programming Languages

java
68154 projects - #9 most used programming language
kotlin
9241 projects

Projects that are alternatives of or similar to Runtimepermission

Kovenant
Kovenant. Promises for Kotlin.
Stars: ✭ 657 (-23.6%)
Mutual labels:  async, rxjava, rx
Ferro
Simple and powerful MVP library for Android
Stars: ✭ 441 (-48.72%)
Mutual labels:  rxjava, rx
Vercel Php
▲ Vercel PHP runtime • vercel-php • now-php • 🐘+ λ = ❤
Stars: ✭ 429 (-50.12%)
Mutual labels:  lambda, runtime
Combinex
Open source implementation for Apple's Combine
Stars: ✭ 496 (-42.33%)
Mutual labels:  async, rx
Rxbluetooth
Android reactive bluetooth
Stars: ✭ 405 (-52.91%)
Mutual labels:  rxjava, rx
Asyncawait
async/await for Android built upon coroutines introduced in Kotlin 1.1
Stars: ✭ 410 (-52.33%)
Mutual labels:  async, coroutines
Rxretrojsoup
A simple API-like from html website (scrapper) for Android, RxJava2 ready !
Stars: ✭ 492 (-42.79%)
Mutual labels:  rxjava, rx
Amp
A non-blocking concurrency framework for PHP applications. 🐘
Stars: ✭ 3,457 (+301.98%)
Mutual labels:  async, coroutines
Reservoir
Android library to easily serialize and cache your objects to disk using key/value pairs.
Stars: ✭ 674 (-21.63%)
Mutual labels:  async, rxjava
Android Startup
🔥The Android Startup library provides a straightforward, performant way to initialize components at the application startup. Both library developers and app developers can use Android Startup to streamline startup sequences and explicitly set the order of initialization.
Stars: ✭ 635 (-26.16%)
Mutual labels:  manifest, async
Kotlin Flow Extensions
Extensions to the Kotlin Flow library.
Stars: ✭ 404 (-53.02%)
Mutual labels:  async, coroutines
Recoil
Asynchronous coroutines for PHP 7.
Stars: ✭ 765 (-11.05%)
Mutual labels:  async, coroutines
Swoole Src
🚀 Coroutine-based concurrency library for PHP
Stars: ✭ 17,175 (+1897.09%)
Mutual labels:  async, coroutines
Actix Net
A collection of lower-level libraries for composable network services.
Stars: ✭ 415 (-51.74%)
Mutual labels:  async, runtime
Freezer
A simple & fluent Android ORM, how can it be easier ? RxJava2 compatible
Stars: ✭ 326 (-62.09%)
Mutual labels:  rxjava, rx
Groupco
PHP的服务化框架。适用于Api、Http Server、Rpc Server;帮助原生PHP项目转向微服务化。出色的性能与支持高并发的协程相结合
Stars: ✭ 473 (-45%)
Mutual labels:  async, coroutines
Inline Activity Result
Receive Activity results inline, without any boilerplate. Optional coroutines and RxJava support.
Stars: ✭ 298 (-65.35%)
Mutual labels:  rxjava, coroutines
Rxgps
Finding current location cannot be easier on Android !
Stars: ✭ 307 (-64.3%)
Mutual labels:  rxjava, rx
Vertx Guide For Java Devs
Vert.x 3 guide for Java developers
Stars: ✭ 500 (-41.86%)
Mutual labels:  async, rxjava
Swiftcoroutine
Swift coroutines for iOS, macOS and Linux.
Stars: ✭ 690 (-19.77%)
Mutual labels:  async, coroutines

Runtime Permission

CircleCI Language

screen

Simpliest way to ask runtime permissions on Android, choose your way :

No need to override Activity or FragmentonPermissionResult(code, permissions, result)using this library, you just have to executue RuntimePermission's methods This will not cut your code flow

General Usage (cross language)

Download

dependencies {
    implementation 'com.github.florent37:runtime-permission:(lastest version)'
}

Detect Permissions

RuntimePermission can automatically check all of your needed permissions

For example, if you add to your AndroidManifest.xml :

screen

You can use askPermission without specifying any permission

For example, in Kotlin:

askPermission(){
   //all of your permissions have been accepted by the user
}.onDeclined { e -> 
   //at least one permission have been declined by the user 
}

screen

Will automatically ask for CONTACTS and LOCALISATION permissions

Manually call permissions

You just have to call askPermission with the list of wanted permissions

In Kotlin:

askPermission(Manifest.permission.READ_CONTACTS, Manifest.permission.ACCESS_FINE_LOCATION){
   //all of your permissions have been accepted by the user
}.onDeclined { e -> 
   //at least one permission have been declined by the user 
}

screen

Will ask for CONTACTS and LOCALISATION permissions

Kotlin-Coroutines

yourScope.launch {
    try {
        val result = askPermission(Manifest.permission.READ_CONTACTS, Manifest.permission.ACCESS_FINE_LOCATION)
        //all permissions already granted or just granted
        //your action
        resultView.setText("Accepted :${result.accepted.toString()}")

    } catch (e: PermissionException) {
        if (e.hasDenied()) {
            appendText(resultView, "Denied :")
            //the list of denied permissions
            e.denied.forEach { permission ->
                appendText(resultView, permission)
            }
            //but you can ask them again, eg:

            AlertDialog.Builder(this@RuntimePermissionMainActivityKotlinCoroutine)
                    .setMessage("Please accept our permissions")
                    .setPositiveButton("yes") { dialog, which ->
                        e.askAgain()
                    }
                    .setNegativeButton("no") { dialog, which ->
                        dialog.dismiss()
                    }
                    .show();
        }

        if (e.hasForeverDenied()) {
            appendText(resultView, "ForeverDenied")
            //the list of forever denied permissions, user has check 'never ask again'
            e.foreverDenied.forEach { permission ->
                appendText(resultView, permission)
            }
            //you need to open setting manually if you really need it
            e.goToSettings();
        }
    }
}

Download

Download

implementation 'com.github.florent37:runtime-permission-kotlin:(last version)'

Kotlin

askPermission(Manifest.permission.READ_CONTACTS, Manifest.permission.ACCESS_FINE_LOCATION){
   //all permissions already granted or just granted
  
   your action
}.onDeclined { e ->
   if (e.hasDenied()) {
       appendText(resultView, "Denied :")
       //the list of denied permissions
       e.denied.forEach {
           appendText(resultView, it)
       }

       AlertDialog.Builder(this@RuntimePermissionMainActivityKotlin)
               .setMessage("Please accept our permissions")
               .setPositiveButton("yes") { dialog, which ->
                   e.askAgain();
               } //ask again
               .setNegativeButton("no") { dialog, which ->
                   dialog.dismiss();
               }
               .show();
   }

   if(e.hasForeverDenied()) {
       appendText(resultView, "ForeverDenied :")
       //the list of forever denied permissions, user has check 'never ask again'
       e.foreverDenied.forEach {
           appendText(resultView, it)
       }
       // you need to open setting manually if you really need it
       e.goToSettings();
   }
}

Download

Download

implementation 'com.github.florent37:runtime-permission-kotlin:(last version)'

RxJava

new RxPermissions(this).request(Manifest.permission.READ_CONTACTS, Manifest.permission.ACCESS_FINE_LOCATION))
    .subscribe(result -> {
        //all permissions already granted or just granted

        your action
    }, throwable -> {
        final PermissionResult result = ((RxPermissions.Error) throwable).getResult();

        if(result.hasDenied()) {
            appendText(resultView, "Denied :");
            //the list of denied permissions
            for (String permission : result.getDenied()) {
                appendText(resultView, permission);
            }
            //permission denied, but you can ask again, eg:


            new AlertDialog.Builder(RuntimePermissionMainActivityRx.this)
                    .setMessage("Please accept our permissions")
                    .setPositiveButton("yes", (dialog, which) -> {
                        result.askAgain();
                    }) // ask again
                    .setNegativeButton("no", (dialog, which) -> {
                        dialog.dismiss();
                    })
                    .show();
        }

        if(result.hasForeverDenied()) {
            appendText(resultView, "ForeverDenied :");
            //the list of forever denied permissions, user has check 'never ask again'
            for (String permission : result.getForeverDenied()) {
                appendText(resultView, permission);
            }
            // you need to open setting manually if you really need it
            result.goToSettings();
        }
    });

Download

implementation 'com.github.florent37:runtime-permission-rx:(last version)'

Java8

askPermission(this)
     .request(Manifest.permission.READ_CONTACTS, Manifest.permission.ACCESS_FINE_LOCATION)

     .onAccepted((result) -> {
         //all permissions already granted or just granted

         your action
     })
     .onDenied((result) -> {
         appendText(resultView, "Denied :");
         //the list of denied permissions
         for (String permission : result.getDenied()) {
             appendText(resultView, permission);
         }
         //permission denied, but you can ask again, eg:

         new AlertDialog.Builder(RuntimePermissionMainActivityJava8.this)
                 .setMessage("Please accept our permissions")
                 .setPositiveButton("yes", (dialog, which) -> {
                     result.askAgain();
                 }) // ask again
                 .setNegativeButton("no", (dialog, which) -> {
                     dialog.dismiss();
                 })
                 .show();

     })
     .onForeverDenied((result) -> {
         appendText(resultView, "ForeverDenied :");
         //the list of forever denied permissions, user has check 'never ask again'
         for (String permission : result.getForeverDenied()) {
             appendText(resultView, permission);
         }
         // you need to open setting manually if you really need it
         result.goToSettings();
     })
     .ask();

Download

Download

implementation 'com.github.florent37:runtime-permission:(last version)'

Java7

askPermission(this, Manifest.permission.READ_CONTACTS, Manifest.permission.ACCESS_FINE_LOCATION)
    .ask(new PermissionListener() {
        @Override
        public void onAccepted(RuntimePermission runtimePermission, List<String> accepted) {
            //all permissions already granted or just granted

            your action
        }

        @Override
        public void onDenied(RuntimePermission runtimePermission, List<String> denied, List<String> foreverDenied) {
            if(permissionResult.hasDenied()) {
                appendText(resultView, "Denied :");
                //the list of denied permissions
                for (String permission : denied) {
                    appendText(resultView, permission);
                }

                //permission denied, but you can ask again, eg:

                new AlertDialog.Builder(RuntimePermissionMainActivityJava7.this)
                        .setMessage("Please accept our permissions")
                        .setPositiveButton("yes", (dialog, which) -> {
                            permissionResult.askAgain();
                        }) // ask again
                        .setNegativeButton("no", (dialog, which) -> {
                            dialog.dismiss();
                        })
                        .show();
            }


            if(permissionResult.hasForeverDenied()) {
                appendText(resultView, "ForeverDenied :");
                //the list of forever denied permissions, user has check 'never ask again'
                for (String permission : foreverDenied) {
                    appendText(resultView, permission);
                }
                // you need to open setting manually if you really need it
                permissionResult.goToSettings();
            }
        }
    });

How to Contribute

We welcome your contributions to this project.

The best way to submit a patch is to send us a pull request.

To report a specific problem or feature request, open a new issue on Github.

Credits

Manifest permission detection has been forked from https://github.com/sensorberg-dev/permission-bitte, thanks Sensorberg GmbH

Author: Florent Champigny

Blog : http://www.tutos-android-france.com/

Fiches Plateau Moto : https://www.fiches-plateau-moto.fr/

Android app on Google Play Follow me on Google+ Follow me on Twitter Follow me on LinkedIn

License

Copyright 2018 florent37, Inc.

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].