private final ActivityResultLauncher<String> requestPermissionLauncher =
registerForActivityResult(new ActivityResultContracts.RequestPermission(), result -> {
if (result) {
Log.e("aonisvasd", "onActivityResult: PERMISSION GRANTED");
} else {
Log.e("aonisvasd", "onActivityResult: PERMISSION DENIED");
}
});
// 使用方式
if(ContextCompat.checkSelfPermission(context,Manifest.permission.CAMERA) == PackageManager.PERMISSION_GRANTED) {
// TODO: do something...
} else {
requestPermissionLauncher.launch(Manifest.permission.CAMERA);
}
private final ActivityResultLauncher<Intent> resultLauncher = registerForActivityResult(new ActivityResultContracts.StartActivityForResult(), result -> {
if (result.getResultCode() == Activity.RESULT_OK) {
}
});