用NotificationCompat创建Notification
发布日期:2021-06-30 18:40:02 浏览次数:3 分类:技术文章

本文共 714 字,大约阅读时间需要 2 分钟。

final NotificationManager mNotificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);//TODO//FLAG_UPDATE_CURRENT:如果构建的PendingIntent已经存在,则替换它final PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);final Notification notification = new NotificationCompat.Builder(context)        .setContentTitle(title)        .setSmallIcon(R.drawable.ic_notification)        .setContentText(content)        .setDefaults(Notification.DEFAULT_ALL)//铃声、闪光、震动均系统默认。        .setContentIntent(pendingIntent)        .setAutoCancel(true)//设置这个标志当用户单击面板就可以让通知将自动取消        .build();mNotificationManager.notify(notificationId, notification);

转载地址:https://linqiarui.blog.csdn.net/article/details/51457038 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!

上一篇:base64加密原理代码实现
下一篇:Android中的通知Notification

发表评论

最新留言

第一次来,支持一个
[***.219.124.196]2024年04月08日 04时06分40秒