googlesamples / easypermissions

Simplify Android M system permissions
https://firebaseopensource.com/projects/googlesamples/easypermissions/
Apache License 2.0
9.87k stars 1.46k forks source link

add autoRequestPermission() API #216

Closed LeonChen1024 closed 6 years ago

LeonChen1024 commented 6 years ago

as usually if app don't have permission we need to request permission,so this API will easy to use.

googlebot commented 6 years ago

Thanks for your pull request. It looks like this may be your first contribution to a Google open source project (if not, look below for help). Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

:memo: Please visit https://cla.developers.google.com/ to sign.

Once you've signed (or fixed any issues), please reply here (e.g. I signed it!) and we'll verify it.


What to do if you already signed the CLA

Individual signers
Corporate signers
LeonChen1024 commented 6 years ago

I signed it!

googlebot commented 6 years ago

CLAs look good, thanks!

SUPERCILEX commented 6 years ago

This actually already exists! The request perms method takes a callback that will be notified immediately if the permission has already been granted.

LeonChen1024 commented 6 years ago

@SUPERCILEX

@AfterPermissionGranted(RC_LOCATION_CONTACTS_PERM)
    public void locationAndContactsTask() {
        if (hasLocationAndContactsPermissions()) {
            // Have permissions, do the thing!
            Toast.makeText(this, "TODO: Location and Contacts things", Toast.LENGTH_LONG).show();
        } else {
            // Ask for both permissions
            EasyPermissions.requestPermissions(
                    this,
                    getString(R.string.rationale_location_contacts),
                    RC_LOCATION_CONTACTS_PERM,
                    LOCATION_AND_CONTACTS);
        }
    }

In sample , we should use the API like that . I think that requesting permission when there is no permission is a very common situation,so ,if there is a API can do this make user avoid from the inconvenient if else is more easy to used.

samtstern commented 6 years ago

@LeonChen1024 thank you for sending this pull request. In my opinion I don't believe the if/else form is inconvenient enough to make us add something like autoRequest. In the future please open an issue before sending a PR for a new feature so that we can discuss it and save you time!

Thanks again for sending such a well-formed PR though! Hope you understand the decision.

LeonChen1024 commented 6 years ago

Thanks , I think i understand that , Sorry for wasting your time and never happen this mistake again.

SUPERCILEX commented 6 years ago

@LeonChen1024 Don't worry about it! 😊 BTW, here's what I meant when I said this already existed:

public void start() {
    // This will call the annotation processor immediately if the permissions are granted, else request them
    EasyPermissions.requestPermissions(
            this,
            getString(R.string.rationale_location_contacts),
            RC_LOCATION_CONTACTS_PERM,
            LOCATION_AND_CONTACTS);
}

@AfterPermissionGranted(RC_LOCATION_CONTACTS_PERM)
public void locationAndContactsTask() {
    Toast.makeText(this, "TODO: Location and Contacts things", Toast.LENGTH_LONG).show();
}
samtstern commented 6 years ago

@LeonChen1024 definitely not a waste of our time! It was an interesting proposal