Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

I came across a Cheese Factory article (google it because I cannot post more than 2 links with my reputation) which explains how to handle the new permissions system for Android Marshmallow. In the article, he references the Permissionsdispatcher library which aims to reduce boilerplate code. So I downloaded the library demo from GitHub but I get an error which says MainActivityPermissionsDispatcher cannot be resolved. From what I can understand, this class should 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);
}
like image 261
charlesfranciscodev Avatar asked Sep 27 '22 03:09

charlesfranciscodev


2 Answers

I'm a developer. Thanks for your using.

  1. Check your IDE's setting whether annotation processing is allowed or not.
  2. You said, "which is a fork of the PermissionsDispatcher repo" but what you mean? Forked the repo and run the sample module?
like image 193
Shintaro Katafuchi Avatar answered Sep 29 '22 23:09

Shintaro Katafuchi


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

You will have to add the @RuntimePermissions Annotation to your activity and a @NeedsPermission Annotation to a method at least.

In your 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 the annotation processing. After building the project you should be able to use the generated class.

like image 43
woley Avatar answered Sep 30 '22 01:09

woley