Android 8.0后Notification的创建方式

本文介绍了在Android 8.0之后如何创建和管理通知,详细阐述了通知的基本构建步骤。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

通知的基本创建方式
private void sendNotification(){
    int notificationId = 222;

    String channelId = "channel_name";

    String channelName = getPackageName();

    NotificationManager manager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);

    //创建NotificationChannel
    NotificationChannel channel = new NotificationChannel(channelId, channelName, NotificationManager.IMPORTANCE_HIGH);
    manager.createNotificationChannel(channel);

    Notification.Builder builder =new Notification.Builder(this, channelId);

    builder.setContentText("This is Content Text");

    builder.setContentTitle("This is title");

    builder.setChannelId(channelId);//创建通知时指定channelID

    builder.setColor(Color.GREEN);//SmallIcon color

    builder.setSmallIcon(R.drawable.ic_launcher_background);

    Notification notification = builder.build();

    manager.notify(notificationId, notification);
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值