小编bae*_*lyn的帖子

Android Studio 如何让通知出现在手机上?

我想创建一个推送通知,管理员可以在其中向所有用户发送通知。我找到了一个教程并遵循它,但它不起作用。我不确定我哪里做错了,但我得到了一个错误提示

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);
            }
        });

Run Code Online (Sandbox Code Playgroud)

java android push-notification

2
推荐指数
1
解决办法
4527
查看次数

标签 统计

android ×1

java ×1

push-notification ×1