android怎么保证notification不重复
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了android怎么保证notification不重复相关的知识,希望对你有一定的参考价值。
参考技术A 谷歌的通知提供了一个唯一的id参数,只要设置不同的id,就可以避免重复:private
void
showNotification(String
title,
Context
context)
int
requestCode
=
(int)
System.currentTimeMillis();
NotificationManager
notificationManager
=
(NotificationManager)
context
.getSystemService(android.content.Context.NOTIFICATION_SERVICE);
Notification
notification
=
new
Notification(R.drawable.ic_launcher,
"90
上门洗车
",
System.currentTimeMillis());
notification.flags
=
Notification.FLAG_AUTO_CANCEL;
notification.defaults
|=
Notification.DEFAULT_VIBRATE;
notification.defaults
|=
Notification.DEFAULT_SOUND;
notification.defaults
|=
Notification.DEFAULT_LIGHTS;
notification.vibrate
=
new
long[]0,
100,
200,
300;
Intent
intent
=
null;
if
(pushType
==
1)
intent
=
new
Intent(context,
Advertisement
.class);
else
if
(pushType
==
2)
intent
=
new
Intent(context,
HomePage.class);
else
if
(pushType
==
3)
intent
=
new
Intent(context,
OrderList.class);
PendingIntent
contentIntent
=
PendingIntent.getActivity(context,
0,
intent,
0);
notification.setLatestEventInfo(context,
"90上门洗车",
title,
contentIntent);
notificationManager.notify(requestCode,
notification);
在这里,我把notify()里面的id参数变成了
时间戳
,编译,运行
以上是关于android怎么保证notification不重复的主要内容,如果未能解决你的问题,请参考以下文章