0

I'm trying to ask for multiple permissions at the same time, and I'm getting this in the log:

W/Activity: Can reqeust only one set of permissions at a time

That line appears a bunch of times, until I accept to grant the permissions, resulting in a delay.

Here's how I ask the permissions:

private void requestPermissions() {

        if (checkingPermissionIsEnabledOrNot()) {
            Toast.makeText(getApplicationContext(), "All Permissions Granted Successfully", Toast.LENGTH_LONG).show();
        }
        // If permission is not enabled then else condition will execute.
        else {
            //Calling method to enable permission.
            RequestMultiplePermission();
        }
    }

public boolean checkingPermissionIsEnabledOrNot() {


        int SecondPermissionResult = ContextCompat.checkSelfPermission(getApplicationContext(),  Manifest.permission.READ_PHONE_STATE);
        int ThirdPermissionResult = ContextCompat.checkSelfPermission(getApplicationContext(),  Manifest.permission.ACCESS_FINE_LOCATION);



        return 
                SecondPermissionResult == PackageManager.PERMISSION_GRANTED && ThirdPermissionResult == PackageManager.PERMISSION_GRANTED;
    }

//Permission function starts from here
    private void RequestMultiplePermission() {
        // Creating String Array with Permissions.
        ActivityCompat.requestPermissions(this, new String[]
                {

                        Manifest.permission.READ_PHONE_STATE,
                        Manifest.permission.ACCESS_FINE_LOCATION
                }, RequestPermissionCode);

    }

 // Calling override method.
    @Override
    public void onRequestPermissionsResult(int requestCode, String permissions[], int[] grantResults) {
        if (grantResults.length > 0) {


            boolean ReadPhoneStatePermission = grantResults[0] == PackageManager.PERMISSION_GRANTED;
            boolean AccesFineLocationPermission = grantResults[1] == PackageManager.PERMISSION_GRANTED;



            if (ReadPhoneStatePermission && AccesFineLocationPermission) {

                Toast.makeText(this, "Permission Granted", Toast.LENGTH_LONG).show();
            } else {
                Toast.makeText(this, "Permission Denied", Toast.LENGTH_LONG).show();

            }
        }

    }

Any idea why that happens and how to fix it?

0 Answers0