How can I use the Permissionsdispatcher library for new Android M runtime permissions?

I came across a Cheese Factory article (google because I cannot post more than two links with my reputation) that explains how to handle the new Android permissions system Marshmallow. In the article, he refers to the Permissionsdispatcher library which aims to reduce the template code. So I downloaded the demo version of the library from GitHub, but I got an error message that says MainActivityPermissionsDispatcher could not be resolved. From what I can understand, this class needs to be generated. How can I generate it to remove the error?

MainActivity.java

 @Override public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) { // delegate the permission handling to generated method // MainActivityPermissionsDispatcher cannot be resolved MainActivityPermissionsDispatcher.onRequestPermissionsResult(this, requestCode, grantResults); } 
+5
source share
2 answers

I am a developer. Thanks for using.

  • Check the IDE setting if annotation processing is allowed or not.
  • You said, "This is the Dispatcher permission permission fork," but what do you mean? Launch the repo and run the sample module?
+3
source

As described here https://github.com/hotchemi/PermissionsDispatcher#must

You need to add the @RuntimePermissions annotation to your activity and the @NeedsPermission annotation to the method at a minimum.

In build.gradle add the following:

 buildscript { dependencies { classpath 'com.neenbedankt.gradle.plugins:android-apt:1.7' } } apply plugin: 'android-apt' dependencies { compile 'com.github.hotchemi:permissionsdispatcher: 1.2.1@aar ' apt 'com.github.hotchemi:permissionsdispatcher-processor:1.2.1' } 

The android-apt plugin will take care of annotation processing. After creating the project, you can use the generated class.

+1
source

Source: https://habr.com/ru/post/1236565/


All Articles