Skip to content
/ hal Public

Hello, Dave. HAL is a simple and light runtime permissions library. It aims to simplify the headache that is the standard runtime permissions API.

Notifications You must be signed in to change notification settings

JStav/hal

Repository files navigation

hal

  1. Generate a HAL instance.
  Hal hal;
  
  @Override protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    hal = Hal.init();
  }
  1. Reroute onRequestPermissionResults callback to HAL
  @Override public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
    super.onRequestPermissionsResult(requestCode, permissions, grantResults);
    hal.onRequestPermissionsResult(requestCode, permissions, grantResults);
  }
  1. Write your listener
    PermissionsResultListener listener = new PermissionsResultListener() {
      @Override public void onPermissionsResult(List<PermissionResult> permissions) {
        // do something 
      }
    };

The PermissionResult object contains the permission that was requested, and the result of the request.

Getters are as follow:

  getPermission();
  isGranted();
  1. Add desired permissions, register listener, and request.
    hal.addPermission(Manifest.permission.READ_EXTERNAL_STORAGE)
        .addPermission(Manifest.permission.READ_CONTACTS)
        .withListener(listener)
        .request(this);

You can add one or many permissions. The request() method allows both activities and fragments.

For added flavor, use openPodBayDoors() instead of request(). They do the same thing.

Actions

Actions are miscellaneous permission related actions that aren't explicitly asking for a permission. Asking the user to enable bluetooth would be one example.

Hal.request(Context context, int actionCode);

Action codes can be found in the base class Action. An example call would be:

Hal.request(context, Action.ACTION_ENABLE_BLUETOOTH);

About

Hello, Dave. HAL is a simple and light runtime permissions library. It aims to simplify the headache that is the standard runtime permissions API.

Topics

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages