我写了两个通知函数。它们都在工作 - 它只是旧版本使用弃用的方法。问题是我的新菜单没有显示在菜单栏上,并且在出现时不会振动或发出噪音。我需要添加什么?
旧版本:
public void createNotification(String message) {
Intent intent = new Intent(this, NotificationService.class);
PendingIntent pi = PendingIntent.getActivity(this, 0, intent, 0);
NotificationManager nm = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
Notification n = new Notification(R.drawable.logo_small, message,
System.currentTimeMillis());
n.setLatestEventInfo(this, message, message, pi);
n.defaults = Notification.DEFAULT_ALL;
nm.notify(12327942 + notidchange, n);
++notidchange;
}
新版本:
public void createNotification(String message) {
//add diff icons and titles later
Intent intent = new Intent(this, NotificationService.class);
PendingIntent pi = PendingIntent.getActivity(this, 0, intent, 0);
NotificationManager nm = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
NotificationCompat.Builder builder = new NotificationCompat.Builder(this)
.setContentTitle(message)
.setContentText(message)
.setSmallIcon(R.drawable.logo_small)
.setAutoCancel(true) //do I want?
.setContentIntent(pi);
nm.notify(12327942 + notidchange++, builder.build());
}
答案 0 :(得分:0)
,把这段代码
Notification notif = builder.build();
notif.flags |= Notification.FLAG_SHOW_LIGHTS;
notif.ledOnMS = 100;
notif.ledOffMS = 100;
notif.defaults = Notification.DEFAULT_ALL;
并替换nm.notify(12327942 + notidchange++, builder.build());
与nm.notify(12327942 + notidchange++, notif);