安卓任务栏显示内容

/**

* 通知栏

*/

private void showNotifyBarInfo() {

/**

    * 创建频道

    */

    //意图

    Intent intent =new Intent(this, MusicPlayerActivity.class);

    intent.putExtra("Notification",true);

    /**

    * 悬而未定的意图

    * 点击之后会触发一些事件

    */

    PendingIntent pendingIntent = PendingIntent.getActivity(this,0,intent,PendingIntent.FLAG_UPDATE_CURRENT);

    //设置管理频道的一些参数

    String id ="channel_1";//channel的id

    String describe ="123";//channel的描述信息

    int importance = NotificationManager.IMPORTANCE_LOW;//channel的重要性

    NotificationChannel channel =new NotificationChannel(id, describe, importance);//生成channel

    /**

    * 创建通知栏

    */

    NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);

    notificationManager.createNotificationChannel(channel);//添加channel

    //设置通知数据

    Notification notification =new Notification.Builder(this,id)//传入通知频道id

            .setCategory(Notification.CATEGORY_MESSAGE)

//设置简单图标

            .setSmallIcon(R.drawable.music_default_bg)

//设置内容标题

            .setContentTitle("321音乐")

//设置内容文本

            .setContentText("正在播放"+getName())

//设置内容意图

            .setContentIntent(pendingIntent)

//构建

            .build();

    notification.flags =Notification.FLAG_ONGOING_EVENT; // 持续监听 点击之后状态栏不消失

    notificationManager.notify(1,notification);//通知管理 开始通知 传入一个通知 和id

}

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容