googlesamples / easypermissions Goto Github PK
View Code? Open in Web Editor NEWSimplify Android M system permissions
Home Page: https://firebaseopensource.com/projects/googlesamples/easypermissions/
License: Apache License 2.0
Simplify Android M system permissions
Home Page: https://firebaseopensource.com/projects/googlesamples/easypermissions/
License: Apache License 2.0
Hi,
I need 'requestCode' in 'onPermissionsGranted' function to uniquely identify the flow.
It would be best if you add them in next update.
it's a weird issue
when i use plugin compile 'pub.devrel:easypermissions:0.1.9'
Everything works perfects
As soon as I moved to latest build compile 'pub.devrel:easypermissions:0.2.1'
I got binary XML exception on floating button, coordinate layouts?
for (Method method : clazz.getDeclaredMethods()) { if (method.isAnnotationPresent(AfterPermissionGranted.class)) { /* more code */ } }
When using a base class (e.g. BaseFragment) which has annoteated AfterPermissionGranted methods then these are not run. The reason seems to be that clazz.getDeclaredMethods() only returns the methods which are declared in the class itself and not the superclass ones.
This might be intented behaviour, but just wanted to check.
Solved problem by modifying code locally in EasyPermissions.java class
if (method.isAnnotationPresent(AfterPermissionGranted.class)) {
to
if (method.getAnnotation(AfterPermissionGranted.class) != null) {
Any method with @AfterPermissionGranted annotation is not executed and the overriden methods onRequestPermissionsResult, onPermissionsGranted, and onPermissionsDenied do not execute for me. I implemented the class inside of a fragment class. I have tried to make the method with the annotation publc and private, both failed.
The permission does get granted/denied so it seems to be partially working for me. I would like to get the code executed soon as the permissions are granted working though.
Error:(404, 23) 错误: 找不到符号
符号: 方法 isAnnotationPresent(Class)
位置: 类型为Method的变量 method
if one use this repository normal,then everything is fine;
but i try to test it :)
step 1:
uninstall the app ,and then install app,then grant all permissions very quickly ,then the app will crash;
i don't see the crash log :( ..
but i reopen the app,and crash again ,and see the log:
02-09 14:14:54.695 3013-3013/com.hgrica.obdclient E/AndroidRuntime: FATAL EXCEPTION: main Process: com.hgrica.obdclient, PID: 3013 java.lang.ClassCastException: com.hgrica.obdclient.view.WelcomeActivity cannot be cast to android.support.v4.app.FragmentActivity at pub.devrel.easypermissions.RationaleDialogClickListener.onClick(RationaleDialogClickListener.java:57) at android.support.v7.app.AlertController$ButtonHandler.handleMessage(AlertController.java:161) at android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loop(Looper.java:150) at android.app.ActivityThread.main(ActivityThread.java:5546) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:794) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:684)
i notice this :com.hgrica.obdclient.view.WelcomeActivity cannot be cast to android.support.v4.app.FragmentActivity
that means i should use a activity that extends FragmentActivity?
but u never mention it..
step2:
uninstall the app,and reinstall the app.oh.still the app crash again.
i notice a important thing: EasyPermissions.hasPermissions(this, PERMISSIONS_ALL) in the method which has @AfterPermissionGranted(REQUEST_ALL)
dosen't work well;i have already granted all permissions,but EasyPermissions.hasPermissions(this, PERMISSIONS_ALL) still return false until i restart the app or just grant the permission(although i have already granted it)again.
:(
here is the activity code :)
`public class WelcomeActivity extends BaseFragmentActivity implements EasyPermissions.PermissionCallbacks{
private static final String TAG = WelcomeActivity.class.getSimpleName();
//all permission i want
public static String[] PERMISSIONS_ALL = {Manifest.permission.READ_EXTERNAL_STORAGE,
Manifest.permission.WRITE_EXTERNAL_STORAGE,Manifest.permission.ACCESS_FINE_LOCATION,
Manifest.permission.ACCESS_COARSE_LOCATION, Manifest.permission.READ_PHONE_STATE
};
//all
public static final int REQUEST_ALL = 4;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_welcome);
requestPermissions();
}
private void requestPermissions() {
requestAllPermissions();
}
@Override
public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {
EasyPermissions.onRequestPermissionsResult(requestCode, permissions, grantResults, this);
}
@Override
public void onPermissionsGranted(int requestCode, List<String> perms) {
LogUtil.d(TAG,"onPermissionsGranted(),requestCode:"+requestCode);
for (String perm:perms){
LogUtil.d(TAG,"onPermissionsGranted(),perm:"+perm);
}
}
@Override
public void onPermissionsDenied(int requestCode, List<String> perms) {
LogUtil.d(TAG,"onPermissionsDenied(),requestCode:"+requestCode);
for (String perm:perms){
LogUtil.d(TAG,"onPermissionsDenied(),perm:"+perm);
}
}
@AfterPermissionGranted(REQUEST_ALL)
private void requestCodeQRCodePermissions() {
if (!EasyPermissions.hasPermissions(this, PERMISSIONS_ALL)) {
LogUtil.d(TAG,"what~~~~~~~~~~~no");
EasyPermissions.requestPermissions(this, "come on", REQUEST_ALL, PERMISSIONS_ALL);
}else {
// Already have permission, do the thing
LogUtil.d(TAG,"what~~~~~~~~~~~yes");
}
}
}`
so i try to do sth for these problem:
step1: i try to make activity extends FragmentActivity..
it work! well..er..fine.
setp2: still finding way.....
so i need your help!!thx
easypermission version -> 0.2.1 phone model -> nexus5 6.0 has bean root
@AfterPermissionGranted(REQUEST_PHONE_PER)
private void methodRequestPhonePer() {
String[] perms = {Manifest.permission.READ_PHONE_STATE};
if (EasyPermissions.hasPermissions(this, perms)) {
// login
login();
return;
}
EasyPermissions.requestPermissions(this, getString(R.string.per_phone), REQUEST_PHONE_PER, perms);
}
private void login() {
new LoginPresenter(TaskProvider.provideTasksRepository(this), this);
mPresenter.start();
}
@Override
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
EasyPermissions.onRequestPermissionsResult(requestCode, permissions, grantResults, this);
}
@Override
public void onPermissionsGranted(int i, List<String> list) {
login();
}
@Override
public void onPermissionsDenied(int i, List<String> list) {
PermissUtils.somePermissionPermanentlyDenied(this, list);
}
Hi, how can i requestPermissions inside the Service? Since the code will throw an exception if it is accessed from outside of activity or fragment.
Thanks :)
Rationale button which showing the message on the first rejection of the permission is not showing any of the buttons like 'ok' or 'cancel'.
User will not get to know what to do in that case.
I checked it on Samsung s6 and Moto G4 plus
i am getting the devicedId in just an util class,how should i do?
This is a normal permission,why the example using it?
Once I denied permission permanently(Never ask) and after that when I try to call the same requestPermission method, app crashes.
If the user rotates while the rationale request is up, we leak the dialog and the request is lost
I don't want the alert dialog shown by the easy permission before the actual permission dialog.
Hello,
upon building your app in Android Studio 2.2 Beta 2 with gradle plugin com.android.tools.build:gradle:2.2.0-beta2, I get the following error:
Error:FAILURE: Build failed with an exception.
- Where:
Script '/Users/igorganapolsky/workspace/git/google/easypermissions/easypermissions/maven.gradle' line: 1- What went wrong:
A problem occurred evaluating script.
Failed to apply plugin [id 'com.github.dcendents.android-maven']
Could not create plugin of type 'AndroidMavenPlugin'.
If I debug the build from commandline, I see the following info:
Caused by: org.gradle.internal.service.UnknownServiceException: No service of type Factory available in ProjectScopeServices.
Any ideas?
Thanks,
Igor
Similar to what was done in #53 for the rationale dialog.
EasyPermissions.requestPermissions(this, "I need this", 100 , perms);
The sentence "I need this" not displayed the very first time in requesting permission, but for further more request it will display.
If I turn permission on and off it again from setting. the sentence not display again for first request!
I am using easypermissions:0.1.8 on LG G4 H815P android 6.0
If I use the fragment how to do that?
I am using EasyPermission from Fragment but I am getting this error: Caller must be an Activity or a Fragment. Help.
if(EasyPermissions.requestPermissions(this, "This App requires certain dangerous permission that you need to activate. Allow...?", PERM, perms)){
//return true here means user has accept to allow viewing the permission prompt
} else {
//return false here exit the app.
}
is it possible to change void and make it boolean.
i want to check the statement above if ever the user clicks cancel he is allowed in the app which i don't want only if return true then allow
in the return false i want to exit the app if he deny the message permission
Image
actually at the moment its not the case because its VOID can you make the change..Thanks in adv...
Library does not work with android.app.Fragment, only with android.support.v4.app.Fragment
In a future version, could we have a single callback for the results, instead of onPermissionsGranted and onPermissionsDenied, perhaps something like
void onPermissionsResults(int resquestCode, List<String> permsGranted, List<String> permsDenied)
This would be much more useful. As it stands, I cannot have one callback that will tell me that I can use to figure both whether all were granted, and if not, which ones were not granted, so I can know whether to continue my application, or notify the user and stop. With two callbacks, its much more difficult.
in HuaWei Mate7 (android 4.4) when i ask for camera permission, i choose refuse ,but show me i have the permission and can not call camera.
what should i do ?
Using only annotations to receive permission results is valid in some simple use cases.
At starting of the app, I have READ_SMS permission and WRITE_EXTERNAL_STORAGE permission after signup.
Now the issue is as soon as I allow READ_SMS permission, it asks me for WRITE_EXTERNAL_STORAGE permission after that only(signup not done). How to stop this behavior and ask user permission only when required.
The RuntimeException thrown in runAnnotatedMethods method in the following if block has wrong message -
if (method.getParameterTypes().length > 0) { throw new RuntimeException( "Cannot execute non-void method " + method.getName()); }
The message should say something like "Cannot execute method [method name] because it is non-void method and/or has input parameters"
I get the following error via crashlyics on a 5.1.1 Samsung SM-A710Y device. It's a one out of 10k. Anyone has an idea how that can happen?
Fatal Exception: java.lang.SecurityException
Client must have ACCESS_FINE_LOCATION permission to request PRIORITY_HIGH_ACCURACY locations.
String[] perms = {Manifest.permission.ACCESS_FINE_LOCATION, Manifest.permission.ACCESS_COARSE_LOCATION};
if (EasyPermissions.hasPermissions(this, perms)) {
LocationServices.FusedLocationApi.requestLocationUpdates( mGoogleApiClient, mLocationRequest, this);
}
when requesting permission in onResume(), i deny the permission with the "Never Ask Again" option,then show AppSettingsDialog. However it seems the onResume() is always running,and the AppSettingsDialog splash all the time.
Support PreferenceFragment if possible
Failed to resolve: pub.devrel:easypermissions:0.1.9
But 0.1.8 still works No Problem.
"---Edit---" It works if I use:
compile 'pub.devrel:easypermissions:0.1.9@aar'
I dont see this ID "rationale_camera" in any file, can u explain what that mean ? and how to implement
thanx
有中文版说明吗?
My use case is that I have this "Shake to get the current location" which I show the request permission rationale dialog when the user shakes.
The tricky part is some users shake more than they should and the dialog appears more than one time.
I am sure this might not be case for most people and the simplest fix would be just
if(!dialog.isShowing()) {
dialog.show();
}
in both requestPermissions
and checkDeniedPermissionsNeverAskAgain
.
If this is trivial, I would just include the source codes in the app and make the change myself.
Otherwise, I could send a PR.
Thanks for the awesome lib!
If i used it in activity.first i refused,then i open it, show a dialog i click confirm it crashed.if i use AppCompatActivity don't have this problem.
java.lang.ClassCastException: com.example.me.androdnewfeature.MainActivity cannot be cast to android.support.v4.app.FragmentActivity at pub.devrel.easypermissions.RationaleDialogClickListener.onClick(RationaleDialogClickListener.java:57) at android.support.v7.app.AlertController$ButtonHandler.handleMessage(AlertController.java:161) at android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loop(Looper.java:154) at android.app.ActivityThread.main(ActivityThread.java:6077) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:865) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:755)
When using the library on an android.app.Fragment, I'm not receiving any callback if the rationale has been shown before the permission request. It works well if the rationale is not displayed.
I've taken a look at the code and it looks like the problem comes from the click listener for the rationale dialog, created here in RationaleDialogClickListener.java :
@RequiresApi(api = Build.VERSION_CODES.HONEYCOMB)
RationaleDialogClickListener(RationaleDialogFragment dialogFragment,
RationaleDialogConfig config,
EasyPermissions.PermissionCallbacks callbacks) {
mHost = dialogFragment.getActivity();
mConfig = config;
mCallbacks = callbacks;
}
We are setting the host as the activity, not the fragment itself.
But then this host is used to perform another permission request, but not using a fragment host will makes it so the activity will not propagate the result to fragments.
What do you think ? Am I missing something ?
Using version 0.2.1
I am sometimes seeing this crash in production:
Exception java.lang.RuntimeException: Failure delivering result ResultInfo{who=@android:requestPermissions:, request=101, result=-1, data=Intent { act=android.content.pm.action.REQUEST_PERMISSIONS VirtualScreenParam=Params{mDisplayId=-1, null, mFlags=0x00000000)} (has extras) }} to activity {com.google.android.apps.santatracker/com.google.android.apps.santatracker.presentquest.MapsActivity}: java.lang.IllegalStateException: Can not perform this action after onSaveInstanceState
android.app.ActivityThread.deliverResults (ActivityThread.java:4925)
android.app.ActivityThread.handleSendResult (ActivityThread.java:4968)
android.app.ActivityThread.access$1600 (ActivityThread.java:222)
android.app.ActivityThread$H.handleMessage (ActivityThread.java:1849)
android.os.Handler.dispatchMessage (Handler.java:102)
android.os.Looper.loop (Looper.java:158)
android.app.ActivityThread.main (ActivityThread.java:7229)
java.lang.reflect.Method.invoke (Method.java)
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run (ZygoteInit.java:1230)
com.android.internal.os.ZygoteInit.main (ZygoteInit.java:1120)
Caused by java.lang.IllegalStateException: Can not perform this action after onSaveInstanceState
android.support.v4.app.FragmentManagerImpl.checkStateLoss (FragmentManager.java:1533)
android.support.v4.app.FragmentManagerImpl.enqueueAction (FragmentManager.java:1551)
android.support.v4.app.BackStackRecord.commitInternal (BackStackRecord.java:696)
android.support.v4.app.BackStackRecord.commit (BackStackRecord.java:662)
android.support.v4.app.DialogFragment.show (DialogFragment.java:139)
pub.devrel.easypermissions.EasyPermissions.showRationaleDialogFragmentCompat (EasyPermissions.java:176)
pub.devrel.easypermissions.EasyPermissions.requestPermissions (EasyPermissions.java:149)
pub.devrel.easypermissions.EasyPermissions.requestPermissions (EasyPermissions.java:104)
why the nexus 6 and nexus6p didn't recevice nougat update anymore . THe release date is 8 -22..Two weeks later ,the old device have not recevice it ...I even want to change my phone to iphone 7 . why ?
THere can't be any tech issuse...The only reason should be you want sell the new nexus ...
This library should just do nothing on pre-M devices, but our API-level checks are too far down the pipeline which creates a lot of code branches that are practically unreachable but just there to satisfy the lint checker and the compiler.
See #61 for some discussion.
I have a HTC D10w phone, but it doesn't work.
`
public void callPhone()
{
Intent intent = new Intent(Intent.ACTION_CALL);
Uri data = Uri.parse("tel:" + "10086");
intent.setData(data);
// first time -> false,
if (ContextCompat.checkSelfPermission(this, Manifest.permission.CALL_PHONE) !=
PackageManager.PERMISSION_GRANTED)
{
// no dialog
ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.CALL_PHONE},
MY_PERMISSIONS_REQUEST_CALL_PHONE);
return;
}
//has dialog
startActivity(intent);
}
@OverRide
public void onRequestPermissionsResult(int requestCode, String[] permissions,
int[] grantResults)
{
// granted,no dialog
if (requestCode == MY_PERMISSIONS_REQUEST_CALL_PHONE)
{
if (grantResults[0] == PackageManager.PERMISSION_GRANTED)
{
callPhone();
} else
{
// Permission Denied
Toast.makeText(this, "Permission Denied", Toast.LENGTH_SHORT).show();
}
return;
}
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
}
`
try it?
Generally, this permission is allowed for most of the devices and APIs. It is a part of SYSTEM_ALERT_WINDOW permission. Following devices and APIs specially need to request it to draw over other apps. For e.g. drawing Chat Heads like Facebook Messenger.
Android KitKat 4.4 - 4.4.2
Android Marshmallow 6.0.0+ (not sure about 6.0.0+)
Xiaomi's Redmi
Meizu phones
I check for this permission like this:
if (!Settings.canDrawOverlays()) {
// request the permission
} else {
// continue, permission is allowed
doSomething();
}
I, also, check that back in onResume()
Can you support this?
Add .setCancelable(false) to AppSettingsDialog.Builder and to EasyPermissions.requestPermissions.
I want user could only press yes or no but couldn`t close dialog by click out of dialog area.
I was looking at Request Permission example in Readme.md. I don't know if this is a bug or not, but private methods with @AfterPermissionGranted annotation will not be executed. I debug and found out in EasyPermissions.java line 176, getMethods() returns public methods according to JavaDoc
I change my method to public and it works.
It might be useful to note that you must have jcenter()
in the build.gradle repositories. I kept getting Error:Failed to resolve: pub.devrel:easypermissions:0.3.0
and was a bit dumbfounded until I realized I only had mavenCentral()
Update: I now see here that Jcenter has been the default for a while...I guess the code I was working on was older than I thought! Feel free to close this issue.
Unrelated: The Android Quickstart says to use 0.2.1
It seems like there is an issue with this as it is calling request permission if user has denied the permission request. App perform slow, i am facing issue with text input if app user has denied the permission, logcat suggests App is requesting permission on continues basis.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.