带有NotificationCompat.Builder的Android状态栏通知。正确的实施方式?
我一直在阅读有关如何正确执行状态栏通知的内容,但大多数解决方案都使用不推荐的函数。我认为NotificationCompat.Builder是解决我问题的最好和最新的解决方案。谁能给我一个示例代码 对于像我这样的新手来说,我发现的最好的例子似乎并不清楚。我不知道是必须在函数中实现代码并调用它,还是必须将代码粘贴到活动区域带有NotificationCompat.Builder的Android状态栏通知。正确的实施方式?,android,notifications,statusbar,Android,Notifications,Statusbar,我一直在阅读有关如何正确执行状态栏通知的内容,但大多数解决方案都使用不推荐的函数。我认为NotificationCompat.Builder是解决我问题的最好和最新的解决方案。谁能给我一个示例代码 对于像我这样的新手来说,我发现的最好的例子似乎并不清楚。我不知道是必须在函数中实现代码并调用它,还是必须将代码粘贴到活动区域 提前感谢您的帮助和时间。最后,这里是创建简单通知的方法: public void createNotification() { // Build noti
提前感谢您的帮助和时间。最后,这里是创建简单通知的方法:
public void createNotification() {
// Build notification
// Actions are just fake
Notification noti = new Notification.Builder(this)
.setContentTitle("Advice")
.setContentText("blahblahblahblah.").setSmallIcon(R.drawable.icon).build();
NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
// hide the notification after its selected
noti.flags |= Notification.FLAG_AUTO_CANCEL;
notificationManager.notify(0, noti);
}
它抛出了一个“调用需要API级别11”错误,但通过右键单击project-->Android工具-->Clean Lint Markers解决了问题。转到此:感谢您的帮助,最后我的应用程序运行良好。谢谢你@简单规划