Giter Club home page Giter Club logo

easypermissions's Introduction

EasyPermissions

This project is forked from EasyPermission, modified some few codes to make it more easier to use, which lets you more focus on your business logic.

中文文档

Feature

  • deleted the annotation,only using the CallBack to deal with the permissions callback.
  • use a way like PermissionGen to request the permission, looking more clearly

Usage

This sample is a standard template sample. Whatever your Android.SDK version is, you can write code like this.

/*
    1. you should implement the EasyPermission.PermissionCallback interface.
*/
public class MainFragment extends Fragment implements EasyPermission.PermissionCallback {
      @Override 
      public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        /*
            request permissions like PermissionGen which looks more clearly 
        */
        EasyPermission.with(this)
            .addRequestCode(RC_SMS_PERM)
            .permissions(Manifest.permission.READ_SMS)
            .rationale(getString(R.string.rationale_sms))
            .request();
    }

    @Override 
    public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions,
            @NonNull int[] grantResults) {
        /*
            pass the OnRequestPermissionsResult to EasyPermission
        */
        EasyPermission.onRequestPermissionsResult(this, requestCode, permissions, grantResults);
    }

    @Override 
    public void onPermissionGranted(int requestCode, List<String> perms) {
        /*
            all permissions are granted, continue doing your business here
        */
        Toast.makeText(getActivity(), "TODO: SMS Granted", Toast.LENGTH_SHORT).show();
    }

    @Override 
    public void onPermissionDenied(int requestCode, List<String> perms) {
        /*
            some permissions denied, toast a info to user 
        */
        Toast.makeText(getActivity(), "TODO: SMS Denied", Toast.LENGTH_SHORT).show();

        // optional, go to the Settings Screen.
        EasyPermission.checkDeniedPermissionsNeverAskAgain(this, "cannot work without permissions", perms);
    }

    @Override 
    public void onActivityResult(int requestCode, int resultCode, Intent data) {
        /*
            backing from Settings Activity, these are standard codes 
        */
        if (requestCode == EasyPermission.SETTINGS_REQ_CODE) {
            if(EasyPermission.hasPermissions(getContext(), Manifest.permission.READ_SMS)){
                // all permissions granted
                // do you business...
            }else{
                // some permissions denied
               Toast.makeText(getContext(),"no permission, can not work",Toast.LENGTH_SHORT).show();
            }
        }
    }
}

easypermissions's People

Contributors

samtstern avatar baiiu avatar alirezaafkar avatar jaibatrik avatar elsennov avatar jmarkovic avatar markmals avatar prempalsingh avatar fly2013 avatar danke77 avatar leedenison avatar

Watchers

James Cloos avatar Mocao 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.