1. public class MainActivity extends Activity{ 
  2.  
  3.     private Button show; 
  4.     private PendingIntent contentIntent; 
  5.     private Intent intent; 
  6.     private NotificationManager manager; 
  7.     private Notification notification; 
  8.  
  9.     @Override 
  10.     protected void onCreate(Bundle savedInstanceState) { 
  11.         super.onCreate(savedInstanceState); 
  12.         setContentView(R.layout.activity_main); 
  13.         intent = new Intent(Intent.ACTION_VIEW);   
  14.         intent.setType("vnd.android-dir/mms-sms");   
  15.  
  16.         contentIntent =PendingIntent.getActivity(getApplicationContext(), 0, intent, 0);
  17.  
  18.         //1.notification进行提示(一闪而过的)时候的图片,提示,以及时间(一般设为当前时间) 
  19.         notification =new Notification(R.drawable.ic_launcher, "有新消息", System.currentTimeMillis()); 
  20.         
  21. //2. 设置下拉status bar出现的  notification标题和具体内容,以及点击notification进行跳转的pendingIntent 
  22.         notification.setLatestEventInfo(getApplicationContext(), "10086", "尊敬的用户您好,最近....", contentIntent); 
  23.         
  24. //3. 实例化NotificationManager 
  25.         manager =(NotificationManager) getSystemService(NOTIFICATION_SERVICE); 
  26.         show = (Button) findViewById(R.id.button); 
  27.         show.setOnClickListener(new View.OnClickListener() { 
  28.  
  29.             @Override 
  30.             public void onClick(View v) { 
  31.  
  32.                 //4. 设置要唤醒的notification的id  
  33.                 manager.notify(0, notification); 
  34.  
  35.             } 
  36.         }); 
  37.  
  38.     } 
  39.  
  40.  
  41.