读书人

Android增添顶部通知(Notification)

发布时间: 2012-09-02 21:00:34 作者: rapoo

Android添加顶部通知(Notification)并处于“正在进行中”(onGoing)
/**
* 添加顶部通知
* @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

读书人网 >Android

热点推荐