【发布时间】:2017-03-02 20:58:18
【问题描述】:
我正在使用 EasyPermissions 检查我的 android 中是否已授予某些权限,如果没有则请求它们。很酷的库,效果很好,但是如果某些权限被拒绝,我仍然没有弄清楚如何处理。
所以基本上你在创建时运行这样的代码来检查
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 );
}
代码分解:如果存在权限,则继续其他请求,这很好。我的问题是,如果在请求期间有人单击从不询问按钮怎么办。 EasyPermissions 的人为此提供了一个功能
EasyPermissions.somePermissionPermanentlyDenied(Splash.this, permsList)
我的困境是在哪里调用此函数,因为请求权限方法不返回任何内容(无效)。我尝试了类似的东西
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 );
}
但它总是在启动时运行被拒绝的权限,而不是当用户在运行时实际单击从不按钮时。任何帮助表示感谢..
链接到 EasyPermissions https://github.com/googlesamples/easypermissions
【问题讨论】:
-
您是否尝试在使用 Easy Permissions 的 Fragment/Activity 中实现 EasyPermissions.PermissionCallbacks?
-
不,请问我该如何调用它?认为这是可选的...
-
是的,实现 EasyPermissions.PermissionCallbacks 然后它会要求你添加方法,然后你可以在那里处理你的拒绝
-
有道理,我试试看
标签: java android permissions android-permissions