Git Product home page Git Product logo

splashauth's Introduction

What

简单易用的andorid M权限相关处理的库,通过极为简单的调用方式实现授权校验、授权申请,开发者可以根据结果反馈做相应的处理。

How

  1. 添加依赖

     implementation 'vip.okfood.auth:1.0.0'
    
  2. 声明权限,在manifest中声明需要授权的权限。 举个栗子如下:

     <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
     <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
     <uses-permission android:name="android.permission.READ_PHONE_STATE" />
     <uses-permission android:name="android.permission.CAMERA" />
    
  3. 项目manifest中添加提示对话框组件

     <activity
         android:name="vip.okfood.permission.SplashAuthUI"
         android:configChanges="keyboardHidden|orientation|screenSize"
         android:theme="@style/permission_splash_auth_ui_theme" />
    
  4. 使用例子如下(共有三种使用方法):

     public class MainActivity extends AppCompatActivity {
    
         @Override
         protected void onCreate(Bundle savedInstanceState) {
             super.onCreate(savedInstanceState);
             setContentView(R.layout.activity_main);
         }
    
         private String[] perms = new String[]{
                 Manifest.permission.WRITE_EXTERNAL_STORAGE,
                 Manifest.permission.READ_EXTERNAL_STORAGE,
                 Manifest.permission.READ_PHONE_STATE,
                 Manifest.permission.CAMERA,
         };
    
         //1.校验是否授权
         public void check(View view) {
             boolean checkResult = SplashAuthUI.check(this, perms);
             Toast.makeText(this, checkResult ? "全部已授权" : "包含未授权", Toast.LENGTH_SHORT).show();
         }
    
         //2.请求授权,在onActivityResult中处理结果
         public void request(View view) {
             SplashAuthUI.launch(this, 100, perms);
         }
    
         @Override
         protected void onActivityResult(int requestCode, int resultCode, Intent data) {
             if(requestCode == 100) {
                 String result = resultCode == RESULT_OK ? "授权成功" : "授权失败";
                 Toast.makeText(this, result, Toast.LENGTH_SHORT).show();
             }
         }
    
         //3.校验并请求授权,若存在未授权则启动申请授权,无法处理结果,需要用户再次点击操作触发已授权后的操作
         public void checkAndRequest(View view) {
             boolean checkResult = SplashAuthUI.checkAndLaunch(this, perms, true);
             Toast.makeText(this, checkResult ? "全部已授权" : "包含未授权", Toast.LENGTH_SHORT).show();
         }
     }
    

splashauth's People

Contributors

leo0618 avatar

Stargazers

hhh avatar UFO avatar

Watchers

James Cloos avatar  avatar

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.