###通知’

###通知’

  1. 建立一个通知管理器 ----- NotificationManager

NotificationManager manager = (NotificationManager)getSystemService(Context.NOTIFICATION_SERVICE);

  1. 创建通知对象------ Notification

Notification notification = new Notification(R.drawable.ic_launcher, "你来了一个通知", System.currentTimeMillis());

   notification.setLatestEventInfo(this, "通知的标题", "正文 ", null);

  1. 加载通知

 manager.notify(1, notification);

###通知’----------制作可点击的通知--------例:打开一个新的通知

  1. 建立一个新的活动
  2. 建立通知管理器

NotificationManager manager = (NotificationManager)getSystemService(Context.NOTIFICATION_SERVICE);

  1. 创建通知对象

Notification notification = new Notification(R.drawable.ic_launcher, "你来了一个通知", System.currentTimeMillis());

  1. 创建一个意图

Intent intent = new Intent(this,ToActivity.class);//此意图是打开TonActivity活动

    PendingIntent pi = PendingIntent.getActivity(this,0,intent,PendingIntent.FLAG_CANCEL_CURRENT);

  1. 加载通知

      notification.setLatestEventInfo(this, "标题", "我是正文(*^__^*", pi);

         manager.notify(1, notification);

原文地址:https://www.cnblogs.com/tangwanzun/p/5702270.html