通知栏设置

一般在service里设置

    

public static NotificationManager nm;

private String _title;
private String _artist;


/** * 当开始播放时,通知栏显示当前播放信息 */ private void ShowNotifcation() { nm = (NotificationManager) getApplicationContext().getSystemService( Context.NOTIFICATION_SERVICE);//获取通知栏系统服务对象 notification = new Notification();// 实例化通知栏 notification.icon = R.drawable.icon;// 为通知栏增加图标 notification.defaults = Notification.DEFAULT_LIGHTS;// 默认灯 notification.flags |= Notification.FLAG_AUTO_CANCEL;// 永远驻留 notification.when = System.currentTimeMillis();// 获得系统时间 notification.tickerText = _title; notification.tickerText = _artist; Intent intent2 = new Intent(getApplicationContext(), PlayMusicActivity.class); intent2.putExtra("_ids", _ids); intent2.putExtra("_titles", _titles); intent2.putExtra("_artists", _artists); intent2.putExtra("position", position); PendingIntent contentIntent = PendingIntent.getActivity( getApplicationContext(), 0, intent2, PendingIntent.FLAG_UPDATE_CURRENT); notification.setLatestEventInfo(getApplicationContext(), "播放中", _title, contentIntent); nm.notify(0, notification); }
原文地址:https://www.cnblogs.com/ct732003684/p/2851425.html