如何处理被拒绝的权限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中,您可以处理您的拒绝状态。 试一试,让我知道它是否对你有效。
相关文章