专栏名称: 安卓开发精选
伯乐在线旗下账号,分享安卓应用相关内容,包括:安卓应用开发、设计和动态等。
目录
相关文章推荐
复利大王  ·  某航离谱瓜! ·  14 小时前  
复利大王  ·  旅行卖淫:白天陪玩晚上陪...警方:严厉打击 ·  14 小时前  
复利大王  ·  湘ya一骨科的瓜? ·  昨天  
复利大王  ·  老同学中捞一捞能不能找到免费P友 ·  昨天  
鸿洋  ·  务必立即拿下软考证(政策红利) ·  2 天前  
51好读  ›  专栏  ›  安卓开发精选

Android Notification 详解——基本操作(下)

安卓开发精选  · 公众号  · android  · 2016-11-27 14:28

正文

请到「今天看啥」查看全文


);

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 )

.







请到「今天看啥」查看全文


推荐文章
复利大王  ·  某航离谱瓜!
14 小时前
复利大王  ·  湘ya一骨科的瓜?
昨天
练瑜伽  ·  深冬里,还是这只鸭陪我过的
8 年前
金乡大蒜辣椒国际交易市场  ·  五一假日菜价是否会上涨?供大于求如何化解?
8 年前
智联招聘  ·  王石:我每天坚持的五个习惯
8 年前