首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 移动开发 > Android >

Android的Notification容易实现方法

2012-06-26 
Android的Notification简单实现方法1、独立编写产生Notification 的方法private static int NOTIFICATION_I

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);
    }

热点排行
Bad Request.