
在Shot:中,在onRequestPermissionsResult中,当用户拒绝权限时,某些设备上的GrantResults返回空,并且某些设备具有值PackageManager.PERMISSION_DENIED.
我采用了一种解决方案,用于基于https://stackoverflow.com/a/31925748/2941375答案来识别用户已选择接受,拒绝和拒绝,而无需再次询问运行时权限.
根据我看到的许多文档,如果用户拒绝权限,则它会返回GrantResults为空
我使用其他代码if(grantResults [0] == PackageManager.PERMISSION_DENIED)在其他代码中抛出Arrayindexoutofbound异常
i have tested code when user decline permission
grantResultsis not
emplty for my case,but i have seen crash report on fabric console forgrantResultsthere is many crash witharrayindexoutofbound,
@OverrIDe public voID onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) { super.onRequestPermissionsResult(requestCode, permissions, grantResults); switch (requestCode) { case PermissionManager.MY_PERMISSIONS_REQUEST_LOCATION_ACCESS: { // If request is cancelled, the result arrays are empty. if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) { defineLocationService.start(this); startNextActivity(0); } else if (grantResults[0] == PackageManager.PERMISSION_DENIED) { boolean showRationale = ActivityCompat.shouldShowRequestPermissionRationale(this, permissions[0]); if (!showRationale) { // user also CHECKED "never ask again" // you can either enable some fall back, // disable features of your app // or open another dialog explaining // again the permission and directing to // the app setting startNextActivity(ARTIFICIAL_DELAY_MILliS); } else if (!PermissionManager.MY_REQUESTED_DIALOG) { PermissionManager.checkLocationPermission(this); } else { startNextActivity(0); } } else { startNextActivity(ARTIFICIAL_DELAY_MILliS); } } } }任何人都可以对此进行任何解释,为什么当用户拒绝权限时,某些设备返回的GrantResults为空,而某些设备返回的GrantResults具有拒绝值.
我已经测试了很多次,但是GrantResults永远不会为空,但是控制台崩溃了,这意味着在某些情况下它为空,并且GrantResults [0]抛出异常.
解决方法:
按照the documentation:
Note: It is possible that the permissions request interaction with the user is interrupted. In this case you will receive empty permissions and results arrays which should be treated as a cancellation.
您要如何处理取消完全取决于您(重新请求许可,将其视为拒绝,等等),因此只需确保在您的代码中考虑到这种情况.
总结以上是内存溢出为你收集整理的android-在onRequestPermissionsResult GrantResults在某些设备上,当用户拒绝权限时返回空全部内容,希望文章能够帮你解决android-在onRequestPermissionsResult GrantResults在某些设备上,当用户拒绝权限时返回空所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)