如何处理被拒绝的权限Android M(EasyPermission) [英] How to Handle Denied Permissions Android M (EasyPermissions)
本文介绍了如何处理被拒绝的权限Android M(EasyPermission)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我使用EasyPermission检查我的Android中是否授予了某些权限,如果没有,则请求它们。很酷的库,工作得很好,但我还没有弄清楚如果某些权限被拒绝时该如何处理。
所以基本上是在Create上运行如下代码来检查
if (EasyPermissions.hasPermissions(Splash.this, perms )) {
TelephonyManager telephonyManager = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
String IMEI = telephonyManager.getDeviceId();
String SimSimSerial = telephonyManager.getSimSerialNumber();
Toast.makeText(Splash.this, "IMEI: " + IMEI + " SimSerial: " + SimSimSerial, Toast.LENGTH_SHORT).show();
} else {
EasyPermissions.requestPermissions(Splash.this, "Without these permissions, the app is unable to successfully complete authentication. Please allow us to access your device so that we can better serve you. " ,PERMS_REQUEST_CODE, perms );
}
代码分解:如果存在权限,则继续其他请求,这很好。我的问题是,如果在请求期间,有人点击了Never Ask按钮,该怎么办?EasyPermises的人对此有一个功能
EasyPermissions.somePermissionPermanentlyDenied(Splash.this, permsList)
我的两难境地是在哪里调用该函数,因为请求权限方法不返回任何内容(Void)。我尝试了类似
的内容if (EasyPermissions.hasPermissions(Splash.this, perms )) {...
} else if (EasyPermissions.somePermissionPermanentlyDenied(Splash.this, permsList)) {
} else {
EasyPermissions.requestPermissions(Splash.this, "Without these permissions, the app is unable to successfully complete authentication. Please allow us to access your device so that we can better serve you. " ,PERMS_REQUEST_CODE, perms );
}
但它总是在启动时运行被拒绝的权限,而不是在运行时用户实际单击Never按钮时运行。如有任何帮助,我们将不胜感激。
指向EasyPermission的链接https://github.com/googlesamples/easypermissions
推荐答案
选中此link。
您必须在此处实现EasyPermissions.PermissionCallbacks,您将获得添加方法,这些方法将是onRequestPermissionsResult、onPermissionsGranted、onPermissionsDened。然后,在onPermissionsDened中,您可以处理您的拒绝状态。 试一试,让我知道它是否对你有效。
这篇关于如何处理被拒绝的权限Android M(EasyPermission)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文