码迷,mamicode.com
首页 > 移动开发 > 详细

android 创建通知栏Notification

时间:2014-06-15 16:16:47      阅读:182      评论:0      收藏:0      [点我收藏+]

标签:notification   notificationmanager   pendingintent   

		///// 第一步:获取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);


更复杂的功能可以查询相关api文档。

android 创建通知栏Notification,布布扣,bubuko.com

android 创建通知栏Notification

标签:notification   notificationmanager   pendingintent   

原文地址:http://blog.csdn.net/qiantujava/article/details/30263189

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!