Context.N
应该是Context.NOTIFICATION_SERVICE
。
System.currentT
应该是System.currentTimeMillis()
。
似乎您正在从某个地方复制代码,但代码被截断了?
这是生成通知的示例方法。
这是基于 Android 的文档:Building a Notification。有关更多详细信息(例如如何显示进度条或扩展视图),请阅读文档。
private static void generateNotification(Context context, String messageTitle, String messageText)
{
// Get notification manager.
final NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
// Setup notification builder.
final NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(context)
.setSmallIcon(R.drawable.ic_notification)
.setContentTitle(messageTitle)
.setContentText(messageText)
.setAutoCancel(true)
.setDefaults(Notification.DEFAULT_ALL);
// Create intent.
final Intent resultIntent = new Intent(context, MainActivity.class);
// Setup task stack builder.
final TaskStackBuilder taskStackBuilder = TaskStackBuilder.create(context);
taskStackBuilder.addParentStack(MainActivity.class);
taskStackBuilder.addNextIntent(resultIntent);
// Create pending intent.
final PendingIntent resultPendingIntent = taskStackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);
// Update notification builder.
notificationBuilder.setContentIntent(resultPendingIntent);
// Post notification.
notificationManager.notify(0, notificationBuilder.build());
}
该类NotificationCompat.Builder
需要 Android 的第 4 版支持库。