当前位置: 代码迷 >> Android >> Android的Notification容易实现方法
  详细解决方案

Android的Notification容易实现方法

热度:52   发布时间:2016-05-01 19:56:36.0
Android的Notification简单实现方法
1、独立编写产生Notification 的方法
private static int NOTIFICATION_ID=R.layout.main;
public  void GreateNotification (){
NotificationManager notificationManager=(NotificationManager) getSystemService(NOTIFICATION_SERVICE);
     Notification notification = new Notification(R.drawable.sun, "天气预报", System.currentTimeMillis());
  PendingIntent contentIntent = PendingIntent.getActivity(this, 1, new Intent(), 1);
  notification.setLatestEventInfo(this, "title", "content", contentIntent);
 
  notificationManager.notify(NOTIFICATION_ID, notification);
    }
2、在需要产生Notification 的地方调用以上方法。
3、取消Notification 的方法:
public  void CanllNotification (){
notificationManager.cancel(NOTIFICATION_ID);
    }
  相关解决方案