flutter-permission-handler icon indicating copy to clipboard operation
flutter-permission-handler copied to clipboard

[Bug]: permissions is already running

Open gghh0408 opened this issue 1 year ago • 3 comments

Please select affected platform(s)

  • [x] Android
  • [ ] iOS
  • [ ] Windows

Steps to reproduce

1.start to get the permission like camera. 2.cancle the permission dialog by gesture.(onrequestpermissionResult will not callback on this moment) 3.start to get the camera permission again. 4.bug happened.

Expected results

I tried to fix this, but I'm not sure if it will affect the others。

My modification plan like it↓:

private boolean isAbleToClearCount = false;

    @PermissionConstants.PermissionStatus
    private int determinePermissionStatus(final @PermissionConstants.PermissionGroup int permission) {
        if (isAbleToClearCount) {
            isAbleToClearCount = false;
            pendingRequestCount = 0;
        }

line 435:
       if (permissionsToRequest.size() > 0) {
            isAbleToClearCount = true;
            final String[] requestPermissions = permissionsToRequest.toArray(new String[0]);
            ActivityCompat.requestPermissions(
                    activity,
                    requestPermissions,
                    PermissionConstants.PERMISSION_CODE);
        }

Looking forward to your reply。

gghh0408 avatar Aug 26 '24 02:08 gghh0408

same

zzf0805 avatar Oct 25 '24 05:10 zzf0805

I encounter the same issue.

Reproduce steps:

  • request a permission
  • use Android gesture to switch to home screen
  • click the app icon to resume app

The permission dialog will disappear and saw this warning in logcat.

onRequestPermissionsResult is called without results. This is probably caused by interfering request codes. If you see this error, please file an issue in flutter-permission-handler, including a list of plugins used by this application: https://github.com/Baseflow/flutter-permission-handler/issues

I try this modification and the problem solved.

    @Override
    public boolean onRequestPermissionsResult(
        int requestCode,
        @NonNull String[] permissions,
        @NonNull int[] grantResults) {

        ...

        if (permissions.length == 0 && grantResults.length == 0) {
            Log.w(PermissionConstants.LOG_TAG, "onRequestPermissionsResult is called without results. This is probably caused by interfering request codes. If you see this error, please file an issue in flutter-permission-handler, including a list of plugins used by this application: https://github.com/Baseflow/flutter-permission-handler/issues");
            pendingRequestCount = 0; // <------ ADD THIS
            return false;
        }

        ...

ShengChangYang avatar Jul 18 '25 09:07 ShengChangYang

Just found the permission_handler_android v13.0.1 fixed the issue with the same solution.

ShengChangYang avatar Jul 30 '25 07:07 ShengChangYang