Hi,I was wondering how can I find the class "MainActivityPermissionsDispatcher",thanks.
Have you tried rebuilding the project? The code is generated by annotation processor.
If you want to look at the source code generated by PermissionsDispatcher, you can either Ctrl+Click (Windows) or Cmd+Click (Mac OS X) on MainActivityPermissionsDispatcher in your code to go to its source file, or look for it in your app module's build folder (build/generated/source/apt).
it's my environment‘s problem,thanks again
@Kevin-Leung can you explain how you solved the problem please. I am having troubles with that, it doesn't create the helper class and I don't know why.
My project uses Java 1.8 and sdk 24. Thanks in advance.
@EnriqueRqox Have you tried rebuild project with Android Studio. It will solve the problem.
@hotchemi Yes, I have thied several times and always the output is:
Error:(59, 9) error: cannot find symbol variable ActivityRequestPermPermissionsDispatcher
Error:(146, 9) error: cannot find symbol variable ActivityRequestPermPermissionsDispatcher
Error:Execution failed for task ':app:compileDebugJavaWithJavac'.
Compilation failed; see the compiler error output for details.
I have look at path that @aurae said before and doesn't generate anything.
My code is the following:
package com.example.enriqueruiz.pruebawikitude;
import android.Manifest;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.StringRes;
import android.support.v4.content.ContextCompat;
import android.support.v7.app.AlertDialog;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;
import java.util.List;
import permissions.dispatcher.NeedsPermission;
import permissions.dispatcher.OnNeverAskAgain;
import permissions.dispatcher.OnPermissionDenied;
import permissions.dispatcher.OnShowRationale;
import permissions.dispatcher.PermissionRequest;
import permissions.dispatcher.RuntimePermissions;
@RuntimePermissions
public class ActivityRequestPerm extends AppCompatActivity {
private static final String TAG = ActivityRequestPerm.class.getSimpleName();
private View parentLayout;
private String[] permissions = {
"android.permission.CAMERA",
"android.permission.ACCESS_FINE_LOCATION",
"android.permission.WRITE_EXTERNAL_STORAGE"};
private int[] hasPermissions = {-1, -1, -1}; // GRANTED=0 ; DENIED=-1
//private String[] namePerm = {"camera", "location", "storage"};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_request_perm);
parentLayout = findViewById(R.id.activity_request_perm);
Button button = (Button) findViewById(R.id.button);
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Log.d(TAG, "onClick: before Intent");
Intent i = new Intent(getApplicationContext(), ActivityMain.class);
startActivity(i);
Log.d(TAG, "onClick: after Intent");
}
});
// NOTE: delegate the permission handling to generated method
//ActivityRequestPermPermissionsDispatcher.showCameraWithCheck(this);
ActivityRequestPermPermissionsDispatcher.checkPermissionsWithCheck(this);
}
@Override
protected void onResume () {
super.onResume();
Log.d(TAG, "onResume");
checkPermissions();
}
/**
* Annotate a method which performs the action that requires one or more permissions
*/
@NeedsPermission( {Manifest.permission.CAMERA, Manifest.permission.ACCESS_FINE_LOCATION, Manifest.permission.WRITE_EXTERNAL_STORAGE} )
void checkPermissions() {
/*getSupportFragmentManager().beginTransaction()
.replace(R.id.sample_content_fragment, CameraPreviewFragment.newInstance())
.addToBackStack("camera")
.commitAllowingStateLoss();*/
hasPermissions[0] = ContextCompat.checkSelfPermission(this, permissions[0]);
hasPermissions[1] = ContextCompat.checkSelfPermission(this, permissions[1]);
hasPermissions[2] = ContextCompat.checkSelfPermission(this, permissions[2]);
Log.d(TAG, "Camera permission: "+hasPermissions[0]);
Log.d(TAG, "Location permission: "+hasPermissions[1]);
Log.d(TAG, "Storage permission: "+hasPermissions[2]);
}
/**
* Annotate a method which explains why the permission/s is/are needed. It passes in a
* PermissionRequest object which can be used to continue or abort the current permission
* request upon user input
* @param request
*/
@OnShowRationale( {Manifest.permission.CAMERA, Manifest.permission.ACCESS_FINE_LOCATION, Manifest.permission.WRITE_EXTERNAL_STORAGE} )
void showRationaleForCamera(PermissionRequest request) {
// NOTE: Show a rationale to explain why the permission is needed, e.g. with a dialog.
// Call proceed() or cancel() on the provided PermissionRequest to continue or abort
showRationaleDialog(R.string.permission_rationale, request);
}
/**
* Annotate a method which is invoked if the user doesn't grant the permissions
*/
@OnPermissionDenied( {Manifest.permission.CAMERA, Manifest.permission.ACCESS_FINE_LOCATION, Manifest.permission.WRITE_EXTERNAL_STORAGE} )
void showDeniedForCamera() {
Toast.makeText(this, R.string.permission_camera_denied, Toast.LENGTH_SHORT).show();
}
/**
* Annotate a method which is invoked if the user chose to have the device "never ask again"
* about a permission
*/
@OnNeverAskAgain( {Manifest.permission.CAMERA, Manifest.permission.ACCESS_FINE_LOCATION, Manifest.permission.WRITE_EXTERNAL_STORAGE} )
void showNeverAskForCamera() {
Toast.makeText(this, R.string.permission_camera_neverask, Toast.LENGTH_SHORT).show();
}
/**
*
* @param messageResId
* @param request
*/
private void showRationaleDialog(@StringRes int messageResId, final PermissionRequest request) {
new AlertDialog.Builder(this)
.setPositiveButton(R.string.button_allow, new DialogInterface.OnClickListener() {
@Override
public void onClick(@NonNull DialogInterface dialog, int which) {
request.proceed();
}
})
.setNegativeButton(R.string.button_deny, new DialogInterface.OnClickListener() {
@Override
public void onClick(@NonNull DialogInterface dialog, int which) {
request.cancel();
}
})
.setCancelable(false)
.setMessage(messageResId)
.show();
}
@Override
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
// NOTE: delegate the permission handling to generated method
ActivityRequestPermPermissionsDispatcher.onRequestPermissionsResult(this, requestCode, grantResults);
}
}
Thanks again.
@EnriqueRqox Did you add android-apt plugin to gradle? To get more info can you give us a sample prj which we can reproduce the problem?
@hotchemi That was the key. I forgot to include the plugin and all works except the helper class. I would have spent the whole day trying to find the problem. Thanks very much!
My pleasure!