![](/img/trans.png)
[英]Targeting S+ (version 31 and above) requires that one of FLAG_IMMUTABLE or FLAG_MUTABLE be specified
[英]Targeting S+ (version 33 ) requires that one of FLAG_IMMUTABLE or FLAG_MUTABLE be specified
應用程序在運行時崩潰並出現以下錯誤:
定位 S+(版本 31 及更高版本)要求在創建 PendingIntent 時指定 FLAG_IMMUTABLE 或 FLAG_MUTABLE 之一。 強烈考慮使用 FLAG_IMMUTABLE,僅當某些功能依賴於 PendingIntent 是可變的時才使用 FLAG_MUTABLE,例如,如果它需要與內聯回復或氣泡一起使用。
我嘗試了所有可用的解決方案,但應用程序仍然在 Android 12 上崩潰。
private Notification buildNotification() {
int playButtonResId = isPaused ? R.drawable.ic_play_arrow_white_24dp : R.drawable.ic_pause_white_24dp;
PendingIntent clickIntent = PendingIntent.getActivity(
this, 1,
new Intent(this, MainActivity.class),
PendingIntent.FLAG_IMMUTABLE);
PendingIntent clickIntent;
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.M) {
clickIntent = PendingIntent.getActivity(
getApplicationContext(),
1,
intent,
PendingIntent.FLAG_IMMUTABLE | PendingIntent.FLAG_UPDATE_CURRENT
);
} else {
clickIntent = PendingIntent.getActivity(getApplicationContext(), 1, intent, 0);
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.