Giter VIP home page Giter VIP logo

onekeyperm's Introduction

OneKeyPerm

一键申请Android权限

OneKeyPerm接入说明

OneKeyPerm不依赖任何业务Activity,支持多进程,只需一句静态代码就可以了

例如

申请权限被拒绝后 不会 自动开启设置页面让用户手动开启权限

OneKeyPerm.request(application, Manifest.permission.CAMERA, "您需要允许相机权限,否则无法使用扫码功能", new OneKeyPerm.OnPermResultListener() {
                    @Override
                    public void onPermResult(String perm, boolean isGrant) {
                        Toast.makeText(MainActivity.this, "请求相机权限 " + isGrant, Toast.LENGTH_SHORT).show();
                    }
                });

或者

申请权限被拒绝后 会 自动开启设置页面让用户手动开启权限

OneKeyPerm.request(application, Manifest.permission.CAMERA, "您需要允许相机权限,否则无法使用扫码功能", new OneKeyPerm.OnPermResultListener() {
                    @Override
                    public void onPermResult(String perm, boolean isGrant) {
                        Toast.makeText(MainActivity.this, "请求相机权限 " + isGrant, Toast.LENGTH_SHORT).show();
                    }
                },true);

原理分析

  • 每次通过context启动透明Activity(PermissionActivity)请求权限

  • 当权限被拒绝后启动另一个透明Activity (WatchAuthorizationActivity),在WatchAuthorizationActivity中再次启动应用详情设置Activity,然后在WatchAuthorizationActivityonActivityResult方法中再次检查是否已经手动授权,并通过Binder(解决多进程问题)通知调用者

备注:收回授权后Android会重启App

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.