Android 分多次(每次一个)请求权限时的onRequestPermissionsResult()方法
程序员文章站
2022-06-05 14:20:11
...
代码
@Override
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
switch (requestCode){
case 1:
switch (permissions[0]){
case Manifest.permission.READ_CONTACTS://权限1
if (grantResults.length > 0 && grantResults[0]==PackageManager.PERMISSION_GRANTED){
readContacts();
}else {
Toast.makeText(this, "You denied the permission", Toast.LENGTH_SHORT).show();
}
break;
case Manifest.permission.CALL_PHONE://权限2
if (grantResults.length > 0 && grantResults[0]==PackageManager.PERMISSION_GRANTED){
call();
} else {
Toast.makeText(this, "You denied the permission", Toast.LENGTH_SHORT).show();
}
break;
default:
}
break;
default:
}
}