六狼论坛

 找回密码
 立即注册

QQ登录

只需一步,快速开始

新浪微博账号登陆

只需一步,快速开始

搜索
查看: 63|回复: 0

Android的Notification简单实现方法

[复制链接]

升级  6%

172

主题

172

主题

172

主题

进士

Rank: 4

积分
530
 楼主| 发表于 2013-1-30 04:13:04 | 显示全部楼层 |阅读模式
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);
    }
您需要登录后才可以回帖 登录 | 立即注册 新浪微博账号登陆

本版积分规则

快速回复 返回顶部 返回列表