亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

為什么通知不顯示在 API 28 中?

為什么通知不顯示在 API 28 中?

不負相思意 2023-03-17 14:24:09
我查看了 android 文檔并且在 StackOverflow 中看到了所有答案,但是,我似乎無法理解為什么我試圖顯示的通知沒有顯示。每當我單擊按鈕時,應用程序不會顯示通知,而是崩潰,有人可以告訴我為什么會發生這種情況嗎?notify_me.setOnClickListener(            new View.OnClickListener() {                @Override                public void onClick(View v) {                    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {                        NotificationChannel channel = new NotificationChannel("miscellaneous", "Hello World", NotificationManager.IMPORTANCE_HIGH);                        channel.setDescription("Hello Brothers and Sisters");                        NotificationManager noti = getSystemService(NotificationManager.class);                        noti.createNotificationChannel(channel);                    }                }            }    );這是堆棧跟蹤E/AndroidRuntime: FATAL EXCEPTION: mainProcess: com.example.test, PID: 27996java.lang.IllegalArgumentException: Reserved id    at android.os.Parcel.createException(Parcel.java:1970)    at android.os.Parcel.readException(Parcel.java:1934)    at android.os.Parcel.readException(Parcel.java:1884)    at android.app.INotificationManager$Stub$Proxy.createNotificationChannels(INotificationManager.java:1888)    at android.app.NotificationManager.createNotificationChannels(NotificationManager.java:577)    at android.app.NotificationManager.createNotificationChannel(NotificationManager.java:565)    at com.example.test.Main4Activity$1.onClick(Main4Activity.java:44)    at android.view.View.performClick(View.java:7352)    at android.widget.TextView.performClick(TextView.java:14177)    at android.view.View.performClickInternal(View.java:7318)    at android.view.View.access$3200(View.java:846)    at android.view.View$PerformClick.run(View.java:27800)    at android.os.Handler.handleCallback(Handler.java:873)
查看完整描述

1 回答

?
波斯汪

TA貢獻1811條經驗 獲得超4個贊

根據錯誤消息,您不能用作"miscellaneous"通知渠道的 ID - 該名稱是專門為不以 API 26 或更高版本為目標的應用程序保留的,用于發布所有沒有附加渠道的通知。

您可以為您的頻道使用任何其他 ID 字符串。


查看完整回答
反對 回復 2023-03-17
  • 1 回答
  • 0 關注
  • 107 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號