今天老师上课上到通知,教材是第一行代码,可能教材上的源码太久了,我在用安卓9的时候,模拟器报错Failed to post notification on channel “null”,在网上查了很久才知道,Notification在android 26以上设置时,需要设置渠道信息才可以正常显示通知,这是
官方文档地址[https://developer.android.google.cn/about/versions/pie/android-9.0]
接下来说说我的解决办法,首先建立布局,布局文件非常简单,里面只有一个发送通知按钮,用于发出一条通知
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<Button
android:id="@+id/send_notice"
android:layout_