---
title: "NotificationManager通知使用"
author: "hualikejava"
date: "2011-03-11T14:07:25Z"
tags: []
categories: ["移动开发"]
slug: "notificationmanager"
draft: false
lastmod: "2011-03-11T14:07:25Z"
id: 953947
url: "https://hualikejava.iteye.com/blog/953947"
---

有些时候需要做类似于电话，短信未读情况，显示在屏幕上方时。就要用到notificationManager通知。
 下面有个列子：
  
```java

NotificationManager manager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
				Notification notification = new Notification(R.drawable.icon,
						"收到任务", System.currentTimeMillis());
				//通知内容
				RemoteViews remoteViews=new RemoteViews(getPackageName(), R.layout.notification);
				remoteViews.setImageViewResource(R.id.image, R.drawable.user);
				remoteViews.setTextViewText(R.id.text, "content");
				notification.contentView=remoteViews;
				
				//点击进入详细内容
				notification.contentIntent=PendingIntent.getActivity(
						LaunchNotificationActivity.this, 0,new Intent(LaunchNotificationActivity.this,ShowContent.class), 0);
				//设置铃音
				notification.flags|=Notification.FLAG_AUTO_CANCEL;
				notification.defaults |= Notification.DEFAULT_SOUND;
				manager.notify(1, notification);
  
```