Android marshmallow request permission?

后端 未结 24 2062
無奈伤痛
無奈伤痛 2020-11-21 06:40

I am currently working on an application that requires several \"dangerous\" permissions. So I tried adding \"ask for permission\" as required in Android Marshmallow(API Lev

24条回答
  •  感情败类
    2020-11-21 07:26

    You can use my library — NoPermission (It's just one class)

    compile 'ru.alexbykov:nopermission:1.1.1'

    Sample

    PermissionHelper permissionHelper = new PermissionHelper(this); //don't use getActivity in fragment!
    
    permissionHelper.check(Manifest.permission.READ_CONTACTS)
                    .onSuccess(this::onSuccess)
                    .onDenied(this::onDenied)
                    .onNeverAskAgain(this::onNeverAskAgain)
                    .run();
    

    onRequestPermissionResult:

     @Override
      public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults)
            permissionHelper.onRequestPermissionsResult(requestCode, permissions, grantResults);
       }
    

    I think api more convenient than EasyPermissions by Google.

提交回复
热议问题