android - XAMARIN.FORMS 安卓 : FLAG_IMMUTABLE needs to be set when targeting Android S+

标签 android xamarin.forms

我现在已经见过几次这个问题,但从未见过 xamarin.forms:

当我尝试在 android 12 上部署时,我得到:

com.interiorcircle.interircircledroid:针对 S+(版本 31 及更高版本)要求在创建 PendingIntent 时指定 FLAG_IMMUTABLE 或 FLAG_MUTABLE 之一。 强烈考虑使用 FLAG_IMMUTABLE,只有在某些功能依赖于 PendingIntent 可变时才使用 FLAG_MUTABLE,例如如果它需要与内联回复或气泡一起使用。

如图: enter image description here

显然,需要设置一个标志,但我不知道在哪里。

有人能帮忙吗?

最佳答案

在我的例子中,以下代码修复了运行时错误:

var pendingIntentFlags = (Build.VERSION.SdkInt >= BuildVersionCodes.S)
                ? PendingIntentFlags.UpdateCurrent | PendingIntentFlags.Mutable
                : PendingIntentFlags.UpdateCurrent;
var pendingActivityIntent = PendingIntent.GetActivity(Application.Context, requestCode, activityIntent, pendingIntentFlags);
var pendingIntent = PendingIntent.GetBroadcast(Application.Context, requestCode, intent, pendingIntentFlags);

关于android - XAMARIN.FORMS 安卓 : FLAG_IMMUTABLE needs to be set when targeting Android S+,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/71056022/

相关文章:

android - 移动 LinearLayout 有困难

android - 在实现Spinner setOnItemSelectedListener之后,我的应用程序崩溃了

android - 背景简历上的密码

c# - Xamarin.Forms - 选择器选择的项目绑定(bind)没有响应

c# - 不同View的ViewModel Initialize方法

c# - 将 xamarin 表单与 IServiceProvider 一起使用

android - 如何通过 JSON 显示从 DB 到 Android 的所有值

xamarin - 1 属性未更新 Xamarin 表单绑定(bind)

xaml - 如何更改 Xamarin.Forms 中条目的边框颜色

android - 具有口味和尺寸的 Gradle 签名