打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
Android添加顶部通知(Notification)并处于“正在进行中”(onGoing...
Android添加顶部通知(Notification)并处于“正在进行中”(onGoing)

用过Android版的QQ的都知道,QQ返回的时候在顶部通知里会出现一个企鹅,表明QQ正在运行,可以拉开通知,点击手机QQ出现主界面,继续运行。

所以我想让自己的软件也出现这么一个通知,并且可以快速的打开查看。

参考资料:

关于notification 的问题

Android应用开发详解 8.3 Notification和NotificationManager的使用 P178

/**
* 添加顶部通知
* @author liuzhao
*/
public void AddNotification(){
//添加通知到顶部任务栏
//获得NotificationManager实例
String service = NOTIFICATION_SERVICE;
nm = (NotificationManager)getSystemService(service);
//实例化Notification
n = new Notification();
//设置显示图标
int icon = R.drawable.ic_launcher_home;
//设置提示信息
String tickerText = “我的程序”;
//显示时间
long when = System.currentTimeMillis();

 

n.icon = icon;
n.tickerText = tickerText;
n.when = when;
//显示在“正在进行中”
n.flags = Notification.FLAG_ONGOING_EVENT;

//实例化Intent
Intent intent = new Intent(tykmAndroid.this,tykmAndroid.class);
//获得PendingIntent
PendingIntent pi = PendingIntent.getActivity(tykmAndroid.this, 0, intent, 0);
//设置事件信息,显示在拉开的里面
n.setLatestEventInfo(tykmAndroid.this, “我的软件”, “我的软件正在运行……”, pi);
//发出通知
nm.notify(ID,n);
}

http://www.liuzhaocn.com/?p=364
本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
【热】打开小程序,算一算2024你的财运
实现Android的消息通知栏
承香墨影 Android--通知之Notification
Android应用图标在状态栏上显示实现原理
Android Intent和PendingIntent的区别详细分析
全面了解Android Notification
Android 4.0 ICS SystemUI浅析——StatusBar加载流程之Not...
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服