当前位置: 移动技术网 > IT编程>移动开发>Android > android中创建通知栏Notification代码实例

android中创建通知栏Notification代码实例

2019年07月24日  | 移动技术网IT编程  | 我要评论

咏柳,曼联 阿贾克斯 录像,2016mba国家线

///// 第一步:获取notificationmanager
		notificationmanager nm = (notificationmanager) 
				getsystemservice(context.notification_service);

		///// 第二步:定义notification
		intent intent = new intent(this, otheractivity.class);
		//pendingintent是待执行的intent
		pendingintent pi = pendingintent.getactivity(this, 0, intent,
				pendingintent.flag_cancel_current);
		notification notification = new notification.builder(this)
				.setcontenttitle("title")
				.setcontenttext("text")
				.setsmallicon(r.drawable.ic_launcher).setcontentintent(pi)
				.build();
		notification.flags = notification.flag_no_clear;
		
		/////第三步:启动通知栏,第一个参数是一个通知的唯一标识
		nm.notify(0, notification);
		
		//关闭通知
		//nm.cancel(0);

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网