【发布时间】:2019-07-13 13:38:33
【问题描述】:
我尝试了所有代码,并尝试了谷歌的官方代码,但在我的设备和模拟器上没有任何工作
我从 YouTube 和 Google 以及许多博客获得了很多代码,但也没有任何效果
//我试试看
NotificationManager notificationManager
= (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
Notification notification = new
Notification.Builder(MainActivity.this)
.setContentTitle("This is a Notification")
.setContentText("Please pay Your Attention here..!")
.setSmallIcon(R.drawable.ic_launcher_foreground)
.setAutoCancel(true)
.build();
notificationManager.notify(CHANNEL_ID1,notification);
}
});
//然后尝试一下
NotificationCompat.Builder builder =
new NotificationCompat.Builder(this,
CHANNEL_ID)
.setSmallIcon(R.drawable.notification_icon)
.setContentTitle(textTitle)
.setContentText(textContent)
.setPriority(NotificationCompat.PRIORITY_DEFAULT);
//没有任何作用
代码应该在 android 8 和 9 上推送通知
如果从 android 4.4 得到太多的工作会更好
【问题讨论】:
-
您是否收到错误、没有任何反应或其他情况?
标签: java android push-notification notifications