NotificationManager notificationManager=(NotificationManager) PlayerService.this.getSystemService(NOTIFICATION_SERVICE);
int ticon=R.drawable.ticon;
//int listPosition=intent.getIntExtra("listPosition", -1);
mp3Infos=MediaUtil.getMp3Infos(PlayerService.this);
Intent intent1=null;
CharSequence tickerText=mp3Infos.get(listPosition).getTitle();
CharSequence artistText=mp3Infos.get(listPosition).getArtist();
long when =System.currentTimeMillis();
Notification notification=new Notification(ticon, tickerText, when);
try {
intent1=new Intent(Intent.ACTION_MAIN);
intent1.addCategory(Intent.CATEGORY_LAUNCHER);
intent1.setClass(com.simple.music.service.PlayerService.this, PlayerActivity.class);
intent1.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK|Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
notification.flags=Notification.FLAG_ONGOING_EVENT;
PendingIntent pgi=PendingIntent.getActivity(this, 0, intent1, 0);
notification.setLatestEventInfo(this,artistText , tickerText, pgi);
notificationManager.notify(1, notification);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
来源:http://blog.csdn.net/xiaoxujie2007_/article/details/7383708