正文
);
mNotificationManager
.
notify
(
i
,
builder
.
build
());
}
}
/**
* 设置FLAG_NO_CLEAR
* 该 flag 表示该通知不能被状态栏的清除按钮给清除掉,也不能被手动清除,但能通过 cancel() 方法清除
* Notification.flags属性可以通过 |= 运算叠加效果
*/
private
void
sendFlagNoClearNotification
()
{
NotificationCompat
.
Builder
builder
=
new
NotificationCompat
.
Builder
(
this
)
.
setSmallIcon
(
R
.
mipmap
.
ic_launcher
)
.
setContentTitle
(
"Send Notification Use FLAG_NO_CLEAR"
)
.
setContentText
(
"Hi,My id is 1,i can't be clear."
);
Notification
notification
=
builder
.
build
();
//设置 Notification 的 flags = FLAG_NO_CLEAR
//FLAG_NO_CLEAR 表示该通知不能被状态栏的清除按钮给清除掉,也不能被手动清除,但能通过 cancel() 方法清除
//flags 可以通过 |= 运算叠加效果
notification
.
flags
|=
Notification
.
FLAG_NO_CLEAR
;
mNotificationManager
.
notify
(
DEFAULT_NOTIFICATION_ID
,
notification
);
}
/**
* 设置FLAG_AUTO_CANCEL
* 该 flag 表示用户单击通知后自动消失
*/
private
void
sendFlagAutoCancelNotification
()
{
//设置一个Intent,不然点击通知不会自动消失
Intent
resultIntent
=
new
Intent
(
this
,
MainActivity
.
class
);
PendingIntent
resultPendingIntent
=
PendingIntent
.
getActivity
(
this
,
0
,
resultIntent
,
PendingIntent
.
FLAG_UPDATE_CURRENT
);
NotificationCompat
.
Builder
builder
=
new
NotificationCompat
.
Builder
(
this
)
.
setSmallIcon
(
R
.
mipmap
.
ic_launcher
)
.
setContentTitle
(
"Send Notification Use FLAG_AUTO_CLEAR"
)
.
setContentText
(
"Hi,My id is 1,i can be clear."
)
.
setContentIntent
(
resultPendingIntent
);
Notification
notification
=
builder
.
build
();
//设置 Notification 的 flags = FLAG_NO_CLEAR
//FLAG_AUTO_CANCEL 表示该通知能被状态栏的清除按钮给清除掉
//等价于 builder.setAutoCancel(true);
notification
.
flags
|=
Notification
.
FLAG_AUTO_CANCEL
;
mNotificationManager
.
notify
(
DEFAULT_NOTIFICATION_ID
,
notification
);
}
/**
* 设置FLAG_ONGOING_EVENT
* 该 flag 表示发起正在运行事件(活动中)
*/
private
void
sendFlagOngoingEventNotification
()
{
NotificationCompat
.
Builder
builder
=
new
NotificationCompat
.
Builder
(
this
)
.
setSmallIcon
(
R
.
mipmap
.
ic_launcher
)
.