从Service中的Notification启动Activity

来源:互联网 发布:大数据数据分析论文 编辑:程序博客网 时间:2024/05/17 12:03
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 blocke.printStackTrace();}


来源:http://blog.csdn.net/xiaoxujie2007_/article/details/7383708

0 0
原创粉丝点击