我查看了 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 字符串。
添加回答
舉報
0/150
提交
取消