- Generate a HAL instance.
Hal hal;
@Override protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
hal = Hal.init();
}
- 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);
}
- 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();
- 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 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);