Android 12 Kotlin-强烈考虑使用Flag_immutable,仅在某些功能取决于悬浮词是可变的情况下才能使用flag_mutable
这是悬念的代码:
val pi =
PendingIntent.getActivity(
applicationContext,
0,
ii,
PendingIntent.FLAG_UPDATE_CURRENT
)
使用它时我会遇到此错误:
java.lang.IllegalArgumentException: de.xxx.xxx: Targeting S+ (version 31 and above) requires that one of FLAG_IMMUTABLE or FLAG_MUTABLE be specified when creating a PendingIntent.
Strongly consider using FLAG_IMMUTABLE, only use FLAG_MUTABLE if some functionality depends on the PendingIntent being mutable, e.g. if it needs to be used with inline replies or bubbles.
我仍然需要更新活动,因此如何添加此flag_immutable
或flag_mutable
到底是,仍然能够更新活动?基于我尝试的答案:
val pi =
PendingIntent.getActivity(
applicationContext,
0,
ii,
PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_IMMUTABLE
)
但是这给出了语法错误!
那么代码应该如何看?
This is the code for pendingIntent:
val pi =
PendingIntent.getActivity(
applicationContext,
0,
ii,
PendingIntent.FLAG_UPDATE_CURRENT
)
I'm getting this error when using it:
java.lang.IllegalArgumentException: de.xxx.xxx: Targeting S+ (version 31 and above) requires that one of FLAG_IMMUTABLE or FLAG_MUTABLE be specified when creating a PendingIntent.
Strongly consider using FLAG_IMMUTABLE, only use FLAG_MUTABLE if some functionality depends on the PendingIntent being mutable, e.g. if it needs to be used with inline replies or bubbles.
I still need the activity to be updated so how can I add this FLAG_IMMUTABLE
or FLAG_MUTABLE
what ever the hell this is and still be able to update the activity? Based on this answer I tried:
val pi =
PendingIntent.getActivity(
applicationContext,
0,
ii,
PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_IMMUTABLE
)
but this gives syntax error!
So how should the code look?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
该问题和答案中目前显示的代码在Java中。您正在Kotlin写作。
在kotlin中,使用
或
或 >::The code presently shown in that question and answer are in Java. You are writing in Kotlin.
In Kotlin, use the
or
bitwise operator: