Kotlin - 具有多个标志语法的 getPendingIntent

itz*_*har 2 android kotlin

我正在尝试像在 Java 代码中一样通知简单的通知

kotlin 中这一行的语法是什么?

stackBuilder.getPendingIntent(0, PendingIntent.FLAG_ONE_SHOT | Intent.FLAG_ACTIVITY_NEW_TASK);
Run Code Online (Sandbox Code Playgroud)

在 kotlin 中,我不能使用“|” 对于 2 个标志,只有这样:

stackBuilder.getPendingIntent(0,PendingIntent.FLAG_ONE_SHOT)
Run Code Online (Sandbox Code Playgroud)

zsm*_*b13 5

您可以在此处的官方文档中找到可用的按位运算。这些都是在 Kotlin 中拼写出来的中缀函数,而不是使用特殊符号。

在您的情况下,您可以执行以下操作:

stackBuilder.getPendingIntent(0, PendingIntent.FLAG_ONE_SHOT or Intent.FLAG_ACTIVITY_NEW_TASK);
Run Code Online (Sandbox Code Playgroud)