安卓任務(wù)欄顯示內(nèi)容

/**

* 通知欄

*/

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

}

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書(shū)系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

  • 首先寫(xiě)個(gè)按鈕。。。。。。。。。。不粘了 按鈕啟動(dòng)一個(gè)startService(new Intent(this,My...
    f786a43611a0閱讀 658評(píng)論 0 0
  • 最近做直播,要求向關(guān)注者發(fā)通知,顯示在通知欄, 記錄下簡(jiǎn)單的使用。 并發(fā)現(xiàn)一個(gè)在魅族手機(jī)上奇葩的坑。。。 直接上代...
    itkluo88閱讀 7,503評(píng)論 0 2
  • 控件 TextView 文本框 第2方法 Button事件處理 Button button1 = find...
    Mzr_e487閱讀 429評(píng)論 0 1
  • 當(dāng)用戶(hù)在使用APP的過(guò)程中,如果某些重要的功能需要及時(shí)提醒用戶(hù)知道而且在不影響用戶(hù)的前提下,我們通常會(huì)使用通知在后...
    烏托邦式的愛(ài)情閱讀 2,121評(píng)論 0 0
  • 一、概念 Notification,是一種具有全局效果的通知,可以在系統(tǒng)的通知欄中顯示。當(dāng)App向系統(tǒng)發(fā)出通知時(shí),...
    TomyZhang閱讀 414評(píng)論 0 0

友情鏈接更多精彩內(nèi)容