Builder (android.content.Context, String) in Builder cannot be applied(android通知)

Builder (android.content.Context, String) in Builder cannot be applied(android通知)
在这里插入图片描述
《第一行代码》通知出错原因:
第一点注意:
书上说要引入support-v4,现在用的大多都是support-v7,本来就已经自动引入;
android版本更新, NotificationCompat.Builder方法更新,参数改变,加了一个string channelId 参数,而channelId的实际作用是将notification进行分类,如设置不同优先级等。也可使用NotificationChannel.getId()设置channelId;
修正:
加一个String类型的参数;
在这里插入图片描述
第二点注意:
点击按钮相应不能用匿名内部类的方法;
在这里插入图片描述
修正:
让MainActivity实现View.OnclickListener,重写onclick方法;
在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/qq_44280408/article/details/103861914