/**
* 通知欄
*/
private void showNotifyBarInfo() {
/**
? ? * 創(chuàng)建頻道
? ? */
? ? //意圖
? ? Intent intent =new Intent(this, MusicPlayerActivity.class);
? ? intent.putExtra("Notification",true);
? ? /**
? ? * 懸而未定的意圖
? ? * 點(diǎn)擊之后會(huì)觸發(fā)一些事件
? ? */
? ? PendingIntent pendingIntent = PendingIntent.getActivity(this,0,intent,PendingIntent.FLAG_UPDATE_CURRENT);
? ? //設(shè)置管理頻道的一些參數(shù)
? ? String id ="channel_1";//channel的id
? ? String describe ="123";//channel的描述信息
? ? int importance = NotificationManager.IMPORTANCE_LOW;//channel的重要性
? ? NotificationChannel channel =new NotificationChannel(id, describe, importance);//生成channel
? ? /**
? ? * 創(chuàng)建通知欄
? ? */
? ? NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
? ? notificationManager.createNotificationChannel(channel);//添加channel
? ? //設(shè)置通知數(shù)據(jù)
? ? Notification notification =new Notification.Builder(this,id)//傳入通知頻道id
? ? ? ? ? ? .setCategory(Notification.CATEGORY_MESSAGE)
//設(shè)置簡(jiǎn)單圖標(biāo)
? ? ? ? ? ? .setSmallIcon(R.drawable.music_default_bg)
//設(shè)置內(nèi)容標(biāo)題
? ? ? ? ? ? .setContentTitle("321音樂(lè)")
//設(shè)置內(nèi)容文本
? ? ? ? ? ? .setContentText("正在播放"+getName())
//設(shè)置內(nèi)容意圖
? ? ? ? ? ? .setContentIntent(pendingIntent)
//構(gòu)建
? ? ? ? ? ? .build();
? ? notification.flags =Notification.FLAG_ONGOING_EVENT; // 持續(xù)監(jiān)聽(tīng) 點(diǎn)擊之后狀態(tài)欄不消失
? ? notificationManager.notify(1,notification);//通知管理 開(kāi)始通知 傳入一個(gè)通知 和id
}