permissions-dispatcher / PermissionsDispatcher

A declarative API to handle Android runtime permissions.
https://github.com/permissions-dispatcher/PermissionsDispatcher
Apache License 2.0
11.21k stars 1.44k forks source link

onRequestPermissionsResult loop callback #690

Closed Zvirtuey closed 3 years ago

Zvirtuey commented 3 years ago

version 4.8.0

When you choose never ask again, onRequestPermissionsResult !!! this method calls back all the time. Seriously affect my program, is there any solution, I can manually stop or other methods?

@Override
    public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
        // NOTE: delegate the permission handling to generated method
        Log.i(getActivityTag(), "call  onRequestPermissionsResult ");
        if (!goSeting) {
            super.onRequestPermissionsResult(requestCode, permissions, grantResults);
            LoginActivityPermissionsDispatcher.onRequestPermissionsResult(this, requestCode, grantResults);
        }
    }

logcat:

09-15 15:06:01.143 14220-14220/com.rzt.newborn I/LoginActivity: call onRequestPermissionsResult 09-15 15:06:01.224 14220-14220/com.rzt.newborn I/LoginActivity: call onRequestPermissionsResult 09-15 15:06:01.315 14220-14220/com.rzt.newborn I/LoginActivity: call onRequestPermissionsResult 09-15 15:06:01.376 14220-14220/com.rzt.newborn I/LoginActivity: call onRequestPermissionsResult 09-15 15:06:01.440 14220-14220/com.rzt.newborn I/LoginActivity: call onRequestPermissionsResult 09-15 15:06:01.509 14220-14220/com.rzt.newborn I/LoginActivity: call onRequestPermissionsResult 09-15 15:06:01.577 14220-14220/com.rzt.newborn I/LoginActivity: call onRequestPermissionsResult 09-15 15:06:01.644 14220-14220/com.rzt.newborn I/LoginActivity: call onRequestPermissionsResult 09-15 15:06:01.746 14220-14220/com.rzt.newborn I/LoginActivity: call onRequestPermissionsResult

hotchemi commented 3 years ago

could you show us the entire code or reproducible example?

Zvirtuey commented 3 years ago

I found the reason, I want to apply for permission when I enter the interface,If you add this, it will appear !!!

@Override protected void onResume() { super.onResume(); LoginActivityPermissionsDispatcher.showCameraWithPermissionCheck(this); }


Add the log:

@OnNeverAskAgain(Manifest.permission.CAMERA) public void showNeverAskForCamera() { Log.w(getActivityTag(), "go setting"); showSettingDialog();

}

@Override public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) { // NOTE: delegate the permission handling to generated method super.onRequestPermissionsResult(requestCode, permissions, grantResults); Log.i(getActivityTag(), " call onRequestPermissionsResult "); LoginActivityPermissionsDispatcher.onRequestPermissionsResult(this, requestCode, grantResults);

}

Logcat: 09-17 10:33:36.178 21161-21161/com.rzt.newborn W/LoginActivity: go setting 09-17 10:33:36.568 21161-21161/com.rzt.newborn I/LoginActivity: call onRequestPermissionsResult 09-17 10:33:36.569 21161-21161/com.rzt.newborn W/LoginActivity: go setting 09-17 10:33:37.019 21161-21161/com.rzt.newborn I/LoginActivity: call onRequestPermissionsResult 09-17 10:33:37.021 21161-21161/com.rzt.newborn W/LoginActivity: go setting 09-17 10:33:37.471 21161-21161/com.rzt.newborn I/LoginActivity: call onRequestPermissionsResult 09-17 10:33:37.472 21161-21161/com.rzt.newborn W/LoginActivity: go setting 09-17 10:33:37.956 21161-21161/com.rzt.newborn I/LoginActivity: call onRequestPermissionsResult 09-17 10:33:37.957 21161-21161/com.rzt.newborn W/LoginActivity: go setting

hotchemi commented 3 years ago

Don't call permission request inside onResume. This is not from the library but Android framework itself.

see: https://github.com/permissions-dispatcher/PermissionsDispatcher/issues/323