Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

direct call to result() when starting from GooglePlay (just after install) #7

Closed
2ndGAB opened this issue Apr 5, 2017 · 1 comment

Comments

@2ndGAB
Copy link

2ndGAB commented Apr 5, 2017

  • [ x] I have verified there are no duplicate active or recent bugs, questions, or requests
  • [ x] I have verified that I am using the latest version of Permission Utils.
  • [x ] I have given my issue a non-generic title.
  • [x ] I have read over the documentation (before asking questions on how to do something).
Include the following:
  • Permission Utils version: 1.0.9
  • Device OS version: 6.0
  • Device Manufacturer: ASUS
  • Device Name: Nexus 7 2013

I've implemented your library like that in my MainActivity

    private void showDialog(final AskAgainCallback.UserResponse response, String title, String msg) {
        new AlertDialog.Builder(this)
                .setTitle(getResources().getString(R.string.dialog_title_warning))
                .setMessage(getResources().getString(R.string.perm_location_explain) +
                        getResources().getString(R.string.perm_storage_explain) +
                        getResources().getString(R.string.perm_calendar_explain)
                )
                .setPositiveButton(getResources().getString(R.string.label_positiveBtnContinue), new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialogInterface, int i) {
                        response.result(true);
                    }
                })
                .setNegativeButton(getResources().getString(R.string.label_negativeBtnCancel), new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialogInterface, int i) {
                        response.result(false);
                    }
                })
                .setCancelable(false)
                .show();
    }

    @Override
    public void result(ArrayList<PermissionEnum> permissionsGranted, ArrayList<PermissionEnum> permissionsDenied, ArrayList<PermissionEnum> permissionsDeniedForever, ArrayList<PermissionEnum> permissionsAsked) {
        List<String> msg = new ArrayList<>();

        int neededPermissions = 0;

        for (PermissionEnum permissionEnum : permissionsGranted) {
            if (PermissionEnum.ACCESS_FINE_LOCATION.equals(permissionEnum)) {
                neededPermissions++;
            } else if (PermissionEnum.WRITE_EXTERNAL_STORAGE.equals(permissionEnum)) {
                neededPermissions++;
            }
        }

        if (neededPermissions >= 2) { // I really need these 2 permissions
            startApp();
        } else {
            msg.add(getResources().getString(R.string.perm_all_refused) + getResources().getString(R.string.perm_go_settings));
        }

        for (PermissionEnum permissionEnum : permissionsDenied) {

            if (PermissionEnum.ACCESS_FINE_LOCATION.equals(permissionEnum)) {
                msg.add(getResources().getString(R.string.perm_location_explain));
            } else if (PermissionEnum.WRITE_EXTERNAL_STORAGE.equals(permissionEnum)) {
                msg.add(getResources().getString(R.string.perm_storage_explain));
            } else if (PermissionEnum.WRITE_CALENDAR.equals(permissionEnum)) {
                msg.add(getResources().getString(R.string.perm_calendar_explain));
            }
        }

        if (permissionsDeniedForever.size() > 0) {
            msg.add(getResources().getString(R.string.perm_go_settings));
        }

        if (msg.size() > 0) {
            String[] items = msg.toArray(new String[msg.size()]);
            new AlertDialog.Builder(this)
                    .setTitle(getResources().getString(R.string.label_DlgTitleInfo))
                    .setItems(items, new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialogInterface, int i) {

                        }
                    })
                    .show();
        }
    }

    @Override
    public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
        PermissionManager.handleResult(requestCode, permissions, grantResults);
    }
Reproduction Steps

If I click on open from the PlayStore, it doesn't ask me any permission and directly displays the msg generated by the else in the following code:

    if (neededPermissions >= 2) {
        startApp();
    } else {
        msg.add(getResources().getString(R.string.perm_all_refused) + getResources().getString(R.string.perm_go_settings));
    }

If I quit and kill the app and restart it, it asks me for the permissions as expected.

I don't see how your result() callback can be directly called.
Any idea?

@2ndGAB 2ndGAB changed the title Not asking for permissons just after install Not asking for permissions just after install Apr 5, 2017
@2ndGAB 2ndGAB changed the title Not asking for permissions just after install direct call to result() when starting from GooglePlay (just after install) Apr 5, 2017
@2ndGAB
Copy link
Author

2ndGAB commented Apr 6, 2017

Hello,
No problem, forget it, I had a remaining chekSelfPerimission() somewhere.

@2ndGAB 2ndGAB closed this as completed Apr 6, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant