我们正在使用SFMC SDK和react native来显示通知对话框弹出,以允许或不允许Android应用程序中的通知。
react-native-marketingcloudsdk(版本7.4.x)Android - 13版本Android Target SDK - 33
在react-native-marketingcould SDK初始化之前,是否有任何方法可以初始化通知弹出框,以注册通知决策(允许/不允许)?
我们尝试了下面的代码,但没有成功。
val launcher = rememberLauncherForActivityResult(
contract = ActivityResultContracts.RequestPermission(),
onResult = { isGranted ->
if (!isGranted) {
if (shouldShowRequestPermissionRationale(Manifest.permission.POST_NOTIFICATIONS)) {
rationalPermissionOpenDialog.value = true
} else {
permissionOpenDialog.value = true
}
} else {
hasNotificationPermission = isGranted
}
}
)
if (rationalPermissionOpenDialog.value) {
ShowRationalPermissionDialog(openDialog = rationalPermissionOpenDialog) {
rationalPermissionOpenDialog.value = false
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
launcher.launch(Manifest.permission.POST_NOTIFICATIONS)
}
}
}
1条答案
按热度按时间unhi4e5o1#
在onesignal初始化的地方添加此代码
https://documentation.onesignal.com/docs/android-13-push-notification-developer-update-guide#step-3-add-notification-permission-prompt