Preliminary knowledge

  1. ActivityCompat class

A Help class provided by Google that is compatible with the Activity features of different Sdk versions and provides some lifecycle interception capabilities

  1. ActivityCompat. PermissionCompatDelegate class

Provides global interception capabilities for requestPermissions and onActivityResult

Technical objectives

  1. Where you can get the Activity context (custom View, Dialog, PopWindow), you can easily get the onActivityResult directly
  2. When used, it should be strictly tied to the host Activity lifecycle. When the host Activity is destroyed, the callback instance is released
  3. Fully compatible with the normal PermissionDelegate Api calls of tripartite libraries or system libraries

The overall design

use

GlobalPermissionCompatDelegate.getInstance().register(activityContext, new ActivityCompat.PermissionCompatDelegate() {
    @Override
    public boolean requestPermissions(@NonNull Activity activity, @NonNull String[] permissions, int requestCode) {
        // your business code
        return false;
    }

    @Override
    public boolean onActivityResult(@NonNull Activity activity, int requestCode, int resultCode, @Nullable Intent data) {
        // your business code
        return false; }});Copy the code

Key Achievements Display

Making the source code

Source address if there is a problem, welcome to communicate and improve!