用过Android版的QQ的都知道,QQ返回的时候在顶部通知里会出现一个企鹅,表明QQ正在运行,可以拉开通知,点击手机QQ出现主界面,继续运行。
所以我想让自己的软件也出现这么一个通知,并且可以快速的打开查看。
参考资料:
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();
* 添加顶部通知
* @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);
}