android添加通知到顶部任务栏
2012-09-11 15:27
513 查看
public class NotificationtestActivity extends Activity { private static final int ID = 1213; private static final String KEY_COUNT="keyCount"; private int count; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); Intent intent=this.getIntent(); count=intent.getIntExtra(KEY_COUNT,0); this.setTitle("这是第"+Integer.toString(count)+"个"); Button btn=(Button) this.findViewById(R.id.button1); btn.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { AddNotification(); NotificationtestActivity.this.finish(); } }); } /** * 添加顶部通知 * @author liuzhao */ public void AddNotification(){ count++; //添加通知到顶部任务栏 //获得NotificationManager实例 String service = NOTIFICATION_SERVICE; NotificationManager nm = (NotificationManager)getSystemService(service); //实例化Notification Notification n = new Notification(); //设置显示图标 int icon = R.drawable.icon; //设置提示信息 String tickerText ="我的程序"; //显示时间 long when = System.currentTimeMillis(); n.icon = icon; n.tickerText = tickerText; n.when = when; //显示在“正在进行中” // n.flags = Notification.FLAG_ONGOING_EVENT; n.flags|=Notification.FLAG_AUTO_CANCEL; //自动终止 //实例化Intent Intent it = new Intent(this,NotificationtestActivity.class); it.putExtra(KEY_COUNT, count); /********************* *获得PendingIntent *FLAG_CANCEL_CURRENT: * 如果当前系统中已经存在一个相同的PendingIntent对象, * 那么就将先将已有的PendingIntent取消,然后重新生成一个PendingIntent对象。 *FLAG_NO_CREATE: * 如果当前系统中不存在相同的PendingIntent对象, * 系统将不会创建该PendingIntent对象而是直接返回null。 *FLAG_ONE_SHOT: * 该PendingIntent只作用一次, * 如果该PendingIntent对象已经触发过一次, * 那么下次再获取该PendingIntent并且再触发时, * 系统将会返回一个SendIntentException,在使用这个标志的时候一定要注意哦。 *FLAG_UPDATE_CURRENT: * 如果系统中已存在该PendingIntent对象, * 那么系统将保留该PendingIntent对象, * 但是会使用新的Intent来更新之前PendingIntent中的Intent对象数据, * 例如更新Intent中的Extras。这个非常有用, * 例如之前提到的,我们需要在每次更新之后更新Intent中的Extras数据, * 达到在不同时机传递给MainActivity不同的参数,实现不同的效果。 *********************/ PendingIntent pi = PendingIntent.getActivity(this, 0, it, PendingIntent.FLAG_UPDATE_CURRENT); //设置事件信息,显示在拉开的里面 n.setLatestEventInfo(NotificationtestActivity.this,"我的软件"+Integer.toString(count), "我的软件正在运行……", pi); //发出通知 nm.notify(ID,n); } }
相关文章推荐
- Android添加顶部通知
- Android添加顶部通知(Notification)并处于“正在进行中”(onGoing)
- Android xmpp开发 asmack获取离线在线添加好友消息 及 好友上线下线通知
- Android使用NotificationManager来进行任务栏通知(使用Bmob第三方推送)
- Android顶部通知栏和系统通知栏的兼容问题
- Android给launch图标添加未读消息通知
- 添加顶部通知(Notification)并处于“正在进行中”(onGoing)
- Android 5.1 Settings添加通知震动,通知音乐的开关功能实现
- Android 4.1.2为通知栏添加wifi开关
- Android中添加常驻通知栏
- AndroidWear 添加多页面到通知
- 为Android2.3添加下拉通知栏的快捷开关
- Android 主页面顶部栏的通知Notification ,可以自定义通知消息栏的风格,并且点击通知栏进人本程序。
- android源码环境下在通知栏中添加快捷开关
- Android中为通知栏添加滚动条
- Android xmpp开发 asmack获取离线在线添加好友消息 及 好友上线下线通知
- Android 顶部下拉刷新添加数据&& 底部上拉刷新添加数据 ScrollListener
- android 通知栏添加按钮点击效果
- 添加顶部通知(Notification)并处于“正在进行中”(onGoing)
- Android View Activity内部顶部通知实现方式收录