Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
This repository was archived by the owner on Oct 3, 2024. It is now read-only.

add autoRequestPermission() API #216

Closed
LeonChen1024 wants to merge 1 commit into googlesamples:master from LeonChen1024:master
Closed

add autoRequestPermission() API #216

LeonChen1024 wants to merge 1 commit into googlesamples:master from LeonChen1024:master

Conversation

@LeonChen1024
Copy link

@LeonChen1024 LeonChen1024 commented May 11, 2018

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

...mission we need to request permission,so this API will easy to use.
Copy link

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).

📝 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

Copy link
Author

I signed it!

Copy link

CLAs look good, thanks!

Copy link
Contributor

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

Copy link
Author

@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.

Copy link
Contributor

@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.

Copy link
Author

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

Copy link
Contributor

@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();
}

Copy link
Contributor

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

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Reviewers

No reviews

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

AltStyle によって変換されたページ (->オリジナル) /