在某些设备上的 onRequestPermissionsResult grantResults return 当用户拒绝权限时为空
In onRequestPermissionsResult grantResults on some device return empty when user decline the permission
In Shot:,In onRequestPermissionsResult
某些设备上的 grantResults return 为空,而某些设备在用户拒绝时具有值 PackageManager.PERMISSION_DENIED
许可。
我已经实施了一个解决方案,用于识别用户已选择 接受、拒绝 和 拒绝不询问再次 获得 运行 时间许可,基于 回答。
根据我看过的许多文档,如果用户拒绝许可,那么它 returns grantResults
为空
我使用的代码 else if (grantResults[0] == PackageManager.PERMISSION_DENIED)
所以在 else if
部分它抛出 Arrayindexoutofbound 异常
i have tested code when user decline permission grantResults
is not
emplty for my case,but i have seen crash report on fabric console for
grantResults
there is many crash with arrayindexoutofbound
,
@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);
}
}
}
}
谁能对此有任何解释,为什么有些设备 return grantResults
是空的,而有些设备 return grantResults
在用户拒绝许可。
我已经测试了很多次但是grantResults
我这边从来没有空过,但是控制台崩溃了,这意味着在某些情况下它是空的并且grantResults[0]
抛出异常。
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.
你想如何处理取消完全取决于你(重新请求许可,将其视为拒绝等),所以请确保在你的代码中考虑到这种情况。
In Shot:,In onRequestPermissionsResult
某些设备上的 grantResults return 为空,而某些设备在用户拒绝时具有值 PackageManager.PERMISSION_DENIED
许可。
我已经实施了一个解决方案,用于识别用户已选择 接受、拒绝 和 拒绝不询问再次 获得 运行 时间许可,基于
根据我看过的许多文档,如果用户拒绝许可,那么它 returns grantResults
为空
我使用的代码 else if (grantResults[0] == PackageManager.PERMISSION_DENIED)
所以在 else if
部分它抛出 Arrayindexoutofbound 异常
i have tested code when user decline permission
grantResults
is not emplty for my case,but i have seen crash report on fabric console forgrantResults
there 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);
}
}
}
}
谁能对此有任何解释,为什么有些设备 return grantResults
是空的,而有些设备 return grantResults
在用户拒绝许可。
我已经测试了很多次但是grantResults
我这边从来没有空过,但是控制台崩溃了,这意味着在某些情况下它是空的并且grantResults[0]
抛出异常。
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.
你想如何处理取消完全取决于你(重新请求许可,将其视为拒绝等),所以请确保在你的代码中考虑到这种情况。