Skip to content
This repository has been archived by the owner on Jul 2, 2021. It is now read-only.

Listener not working properly on Configuration Change #267

Closed
mshalomdave opened this issue Aug 13, 2020 · 8 comments
Closed

Listener not working properly on Configuration Change #267

mshalomdave opened this issue Aug 13, 2020 · 8 comments

Comments

@mshalomdave
Copy link

mshalomdave commented Aug 13, 2020

Expected behavior

Greetings, It seems MultiplePermissionsListener doesn't work for the current activity on configuration change(android:configChanges="orientation|screenSize|keyboardHidden") that is on orientation change

Actual behavior

It seems that on rotation the Activity gets a different identifier hence the listener won't be able to run the given method on "report.areAllPermissionsGranted()".
The good thing is that the permissions are granted but the user will have to click the View again in order to run the method.

Steps to reproduce

On click of a given View, the onProfileImageClick method is called as specified below:

public interface PickerOptionListener{
void onTakeCameraSelected();
 void onChooseGallerySelected();}

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
      //Other Code}

  private void onProfileImageClick() {
       Dexter.withActivity(this).withPermissions(Manifest.permission.CAMERA, Manifest.permission.WRITE_EXTERNAL_STORAGE).withListener(new MultiplePermissionsListener() {
        @Override
        public void onPermissionsChecked(MultiplePermissionsReport report){
            if (report.areAllPermissionsGranted()){
                showImagePickerOptions();
            }
            if (report.isAnyPermissionPermanentlyDenied()) {
                showSettingsDialog();
            }
        }
        @Override
        public void onPermissionRationaleShouldBeShown(List<PermissionRequest> permissions, PermissionToken token) {
            token.continuePermissionRequest();
        }
    }).check();
}

private void showImagePickerOptions() {
          MainActivity.showImagePickerOptions(this, new MainActivity.PickerOptionListener() {
        @Override
        public void onTakeCameraSelected() {
            launchCameraIntent();
        }
        @Override
        public void onChooseGallerySelected() {
            launchGalleryIntent();
        }
    });
}

private void showSettingsDialog() {
    AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this);
    builder.setTitle(getString(R.string.dialog_permission_title));
    builder.setMessage(getString(R.string.dialog_permission_message));
    builder.setPositiveButton(getString(R.string.go_to_settings), (dialog, which) -> {
        dialog.cancel();
        openSettings();
    });
    builder.setNegativeButton(getString(android.R.string.cancel), (dialog, which) -> dialog.cancel());
    builder.show();
}
 public static void showImagePickerOptions(Context context, MainActivity.PickerOptionListener listener){AlertDialog.Builder builder = new AlertDialog.Builder(context);
    builder.setTitle(context.getString(R.string.lbl_set_profile_photo));
    String[] photos = {context.getString(R.string.lbl_take_camera_picture), context.getString(R.string.lbl_choose_from_gallery)};
    builder.setItems(photos, (dialog, which) -> {
        switch (which) {
            case 0:
                listener.onTakeCameraSelected();
                break;
            case 1:
                listener.onChooseGallerySelected();
                break;
        }
    });
   Dialog myDialog = builder.create();
    myDialog.show();}

Version of the library

6.0.2

@mshalomdave mshalomdave changed the title How can I know when the Permissions are granted? Listener not working properly on Configuration Change Aug 13, 2020
@pedrovgs
Copy link
Contributor

Hey @mshalomdave could you please try to update the library to the latest version? There are some fixes we introduced in the last releases that could fix the issue.

@mshalomdave
Copy link
Author

mshalomdave commented Aug 26, 2020

Hello @pedrovgs. Appreciate the response. I have done as you have suggested (V. 6.2.1) but unfortunately, it's still happening. Just to add in something to what I said above. This happens when I had clicked the View and in case of no permissions granted, the Permission Dialog Appears should I rotate the screen as I am granting the permissions then,(I believe the activity gets a different identifier) and then the granting of permissions may still proceed and will work well but won't be able to call the method. Not sure if it's because it doesn't recognize the current activity after rotation.

@pedrovgs
Copy link
Contributor

@pedrovgs could you please create a simple repository reproducing the issue? This would help us a lot with the fix.

@mshalomdave
Copy link
Author

Sorry for the delay in my response. I have created a Repository(https://github.com/mshalomdave/DexterRepo). So am clarifying on the issue:
This happens when I had clicked the View and in case of no permissions granted, the Permission Dialog Appears should I rotate the screen as I am granting the permissions then,(I believe the context gets a different identifier) and then the granting of permissions may still proceed and will work well but won't be able to call the method. Not sure if it's because it doesn't recognize the current context after rotation.
The good thing is that the permissions are granted but the user will have to click the View again in order to run the method.

@pedrovgs
Copy link
Contributor

pedrovgs commented Nov 9, 2020

@mshalomdave I'm running the code of the provided example and I don't see what's wrong. I'm afraid I don't understand where the issue is. Could you please a list of steps to reproduce the error in the sample provided and the expected behavior?

@ShandyukSergey
Copy link

Faced with the same issue, onPermissionsChecked doesn't call after configuration change. I was able to reproduce the issue with provided sample by @mshalomdave

STR:

  1. Click avatar icon(permissions dialog is showing)
  2. Change screen orientation to landscape
  3. Click 'Allow' button on permissions dialog
  4. Click 'Allow' button on permissions dialog once more
    AR: onPermissionsChecked didn't trigger
    ER: onPermissionsChecked have triggered

@mshalomdave
Copy link
Author

Apologies for the late response. What @ShandyukSergey has said is exactly the issue

@pedrovgs
Copy link
Contributor

I'm afraid @mshalomdave this is a Dexter known issue we face due to the activity being recreated when the screen is rotated. If you don't mind we will keep reviewing the issue in #276

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants