通知没有在android中显示时间

时间:2015-06-19 11:12:08

标签: android

我创建了自定义通知,我无法在通知栏中显示当前时间..即使我显示System.currentTimeMillis(),也不会显示。

final Notification notification = new Notification(R.drawable.notificationicon, context.getResources().getString(R.string.notificationheadingtext), System.currentTimeMillis());
            notification.flags = notification.flags | Notification.FLAG_ONGOING_EVENT;
            notification.when = System.currentTimeMillis();
            int currentapiVersion = android.os.Build.VERSION.SDK_INT;
            if (currentapiVersion > 20)
            {
                notification.contentView = new RemoteViews(getApplicationContext().getPackageName(), R.layout.notification_process);    
            }
            else
            {
                notification.contentView = new RemoteViews(getApplicationContext().getPackageName(), R.layout.notification_process_lowerversion);
            }

            Uri alarmSound = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
            notification.sound = alarmSound;
            notification.contentIntent = pendingIntent;
            notification.contentView.setImageViewResource(R.id.status_icon, R.drawable.ic_launcher);
            notification.contentView.setTextViewText(R.id.status_text, context.getResources().getString(R.string.notificationheadingtext));

            notificationManager.notify(42, notification);

1 个答案:

答案 0 :(得分:0)

不推荐使用通知类。使用NotificationCompat。阅读此tutorial