我想创建一个推送通知,管理员可以发送通知给所有用户。我找到了一个教程,并按照它,但它不工作。我不知道我做错了什么,但我得到的错误说Developer Warning for package "... " Failed to post notification on channel "null"
b1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String tittle = ed1.getText().toString().trim();
String subject = ed2.getText().toString().trim();
String body = ed3.getText().toString().trim();
NotificationManager notif = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
Notification notify = new Notification.Builder
(getApplicationContext()).setContentTitle(tittle).setContentText(body).
setContentTitle(subject).setSmallIcon(R.drawable.ps).build();
notify.flags |= Notification.FLAG_AUTO_CANCEL;
notif.notify(0, notify);
}
});
2条答案
按热度按时间8hhllhi21#
在Oreo SDK之后,你必须创建通知通道才能显示通知,请查看以下方法以供参考:
如何使用此方法:
wtlkbnrh2#