我有一个前台服务,通知我每秒更新一次作为计时器。这在我的 android 4.1 模拟器上运行良好。在 Galaxy Nexus 手机上,通知显示为新通知,每次更新时都有动画。这是为什么?相同的 android 版本,但我只在 Galaxy Nexus 上发现了这种行为。
private void postNotification(Context context, int notificationId, String title, String text, String ticker, boolean service) {
Intent intent = new Intent(context, MyActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP|Intent.FLAG_ACTIVITY_SINGLE_TOP);
PendingIntent contentIntent = PendingIntent.getActivity(context, notificationId, intent, 0);
@SuppressWarnings("static-access")
NotificationManager nm = (NotificationManager) context.getSystemService(context.NOTIFICATION_SERVICE);
NotificationCompat.Builder builder = new NotificationCompat.Builder(context);
builder.setContentTitle(title);
builder.setContentText(text);
if(ticker.length() > 0)
builder.setTicker(ticker);
builder.setSmallIcon(R.drawable.notification);
builder.setContentIntent(contentIntent);
builder.setOngoing(service);
nm.notify(null, notificationId, builder.getNotification());
startForeground(notificationId, builder.getNotification());
}