Notification使用举例


<ul style="margin-top: 0px; margin-bottom: 0px; font-family: 微软雅黑; font-size: 14px; line-height: 21px;"><li style="background-color: inherit;"><span style="background-color: inherit; color: rgb(0, 112, 192); font-family: 宋体; font-size: 12pt;">创建一个<span style="font-family:Calibri;background-color: inherit;">Notification</span><span style="font-family:宋体;background-color: inherit;">的步骤。</span></span></li></ul><p style="margin-top: 5px; margin-bottom: 5px; font-family: 微软雅黑; font-size: 14px; line-height: 21px;"><span style="background-color: inherit; color: rgb(0, 112, 192); font-family: 宋体; font-size: 12pt;">思路:①得到<span style="font-family:Calibri;background-color: inherit;">NotificationManager</span><span style="font-family:宋体;background-color: inherit;">的引用;②初始化一个</span><span style="font-family:Calibri;background-color: inherit;">Notification</span><span style="font-family:宋体;background-color: inherit;">对象;③设置</span><span style="font-family:Calibri;background-color: inherit;">Notification</span><span style="font-family:宋体;background-color: inherit;">的参数;④使用</span><span style="font-family:Calibri;background-color: inherit;">NotificationManager</span><span style="font-family:宋体;background-color: inherit;">的</span><span style="font-family:Calibri;background-color: inherit;">notify(int, Notification)</span><span style="font-family:宋体;background-color: inherit;">方法发出通知。</span></span></p>


<span style="font-size:18px;">public void initNotifi() {

		String ns = Context.NOTIFICATION_SERVICE;</span>
<span style="font-size:18px;"><span style="white-space:pre">		</span><strong>//得到NotificationManager的引用</strong>
		mNotificationManager = (NotificationManager) getActivity()
				.getSystemService(ns);
<span style="white-space:pre">	<strong>	</strong></span><strong>//初始化一个Notification对象,并设置参数,闪灯、声音、icon</strong>
		notification = new Notification();
		notification.defaults |= Notification.DEFAULT_SOUND;
		notification.defaults |= Notification.DEFAULT_LIGHTS;
		notification.icon = R.drawable.shop;
		notification.when = System.currentTimeMillis();

		context = getActivity().getApplicationContext();
		contentTitle = "简付";
		contentText = "买单成功,点击查看!";
	}</span>


<span style="font-size:18px;">public void onClick(View v) {
		switch (v.getId()) {
		case R.id.bt_maidanimdia:
			<strong>//<span style="color: rgb(0, 112, 192); font-family: 宋体; font-size: 16px; line-height: 21px; white-space: pre; background-color: inherit;">使用</span><span style="color: rgb(0, 112, 192); font-size: 16px; line-height: 21px; white-space: pre; font-family: Calibri; background-color: inherit;">NotificationManager</span><span style="color: rgb(0, 112, 192); font-family: 宋体; font-size: 16px; line-height: 21px; white-space: pre; background-color: inherit;">的</span><span style="color: rgb(0, 112, 192); font-size: 16px; line-height: 21px; white-space: pre; font-family: Calibri; background-color: inherit;">notify(int, Notification)</span><span style="color: rgb(0, 112, 192); font-family: 宋体; font-size: 16px; line-height: 21px; white-space: pre; background-color: inherit;">方法发出通知。</span></strong>
			Intent notificationIntent = new Intent(getActivity(),
					CardTxnDetailsActivity.class);
			contentIntent = PendingIntent.getActivity(getActivity(), 0,
					notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT);
			notification.setLatestEventInfo(context, contentTitle, contentText,
					contentIntent);
			mNotificationManager.notify(MAIDAN_ID, <strong>notification</strong>);
			getActivity().finish();
			break;</span>



                
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值