// 获取系统通知服务
NotificationManager notificationManager = (NotificationManager) mContext
.getSystemService(Service.NOTIFICATION_SERVICE);
// 创建Intent
Intent notificationIntent = new Intent(mContext,
AddAniversaryActivity.class);
PendingIntent pendingIntent = PendingIntent.getActivity(mContext,
0x110, notificationIntent, Intent.FLAG_ACTIVITY_NEW_TASK);
// 旧版方法,用于兼容
// 创建新通知实例
Notification notification = new Notification(iconID,
title == null ? "提醒" : title, System.currentTimeMillis());
// 设置事件消息
notification.setLatestEventInfo(mContext, title == null ? "提醒" : title,
content, pendingIntent);
// 发送通知
// iconID为唯一的标识
notificationManager.notify(iconID, notification);
// 以下为新版的方法,旧版无法使用
// Notification.Builder notificationBuilder = new Builder(mContext);
// notificationBuilder.setWhen(System.currentTimeMillis());
// notificationBuilder.setSmallIcon(iconID);
// notificationBuilder.setContentTitle(title == null ? "提醒" : title);
// notificationBuilder.setContentText(content == null ? "您有一个提醒没有查看!"
// : content);
// notificationBuilder.setContentIntent(pendingIntent);
//
// notificationManager.notify((int) NumberUtil.getRid(),
// notificationBuilder.getNotification());
Android-Notification
最新推荐文章于 2021-02-20 15:15:35 发布