android中Notification的用法

总结4步

1 获取通知对象

2新建建Notification

3关联意图

4执行通知

案例如下


<span style="font-size:18px;"></span>
<span style="font-size:18px;">private void button1() {
		count++;
		NotificationManager manager = (NotificationManager) MainActivity.this
				.getSystemService(Context.NOTIFICATION_SERVICE);
		Notification notification = new Notification(R.drawable.ic_launcher,
				"我是通知", System.currentTimeMillis());
		notification.flags = Notification.FLAG_AUTO_CANCEL;
		notification.number = count;
		Intent it = new Intent(Intent.ACTION_CALL, Uri.parse("tel:110"));
		it.putExtra("name", "name" + count);
		PendingIntent pendingIntent = PendingIntent.getActivity(
				getApplicationContext(), 12, it,
				PendingIntent.FLAG_CANCEL_CURRENT);
		notification.setLatestEventInfo(this, "标题", "启动多条显示一条", pendingIntent);
		manager.notify(100, notification);
	}
</span>
执行多条但是只显示一次,点击只执行一次,只显示一次与 manager.notify(n, notification);中的n有关,n是固定的只显示一次,

只执行一次与PendingIntent pendingIntent = PendingIntent.getActivity(getApplicationContext(), 12, it,PendingIntent.FLAG_CANCEL_CURRENT);中的数字有关,相同只执行一次,不相同,可执行多次




其他的boutton事件,只要根据以上规律就可以做出,

自定义格式,除了一其他的自定义style一样,还有必须加载

 RemoteViews contentView = new RemoteViews(getPackageName(), R.layout.自定义的style);  

notification.contentView = contentView;  

就可以了


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值