---
title: "Notifition与NotifitionManager的使用与学习"
author: "mmdev"
date: "2012-12-12T11:16:00Z"
tags: []
slug: "notifition-notifitionmanager"
draft: false
lastmod: "2013-01-05T09:53:21Z"
id: 1761150
url: "https://mmdev.iteye.com/blog/1761150"
---

```
package wanxian.notification;

import android.app.Activity;
import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;

public class MainActivity extends Activity {
	private Button mButton01,mButton02,mButton03,mButton04;
	private NotificationManager nm;
	private Intent mIntent;
	private Notification mNotification;
	private PendingIntent mPendingIntent;
	
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        nm = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
        mButton01=(Button) findViewById(R.id.button01);
        mButton02=(Button) findViewById(R.id.button02);
        mButton03=(Button) findViewById(R.id.button03);
        mButton04=(Button) findViewById(R.id.button04);
        
        mIntent = new Intent(MainActivity.this,MyTest.class);
        mPendingIntent = PendingIntent.getActivity(MainActivity.this, 0, mIntent, 0);
        
        mNotification = new Notification();
        mButton01.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				mNotification.icon=R.drawable.ic_launcher;
				mNotification.tickerText="Button01通知内容";
				mNotification.defaults=Notification.DEFAULT_SOUND;
				mNotification.setLatestEventInfo(MainActivity.this, "Button01", "Button01通知", mPendingIntent);
				nm.notify(0,mNotification);
				
			}
		});
    }
}
```