Android 实现应用通知效果

本文介绍了一个简单的Android应用程序示例,该示例展示了如何创建并发送一个包含特定标题和内容的通知。通过实例化NotificationCompat.Builder并设置相关属性如标题、内容、图标等,最终通过NotificationManager发送出去。

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

    public void send(View view){
         //实例化通知
        NotificationCompat.Builder builder=new NotificationCompat.Builder(this);
        builder.setContentTitle("提示");
        builder.setContentText("中奖啦!请先汇款到XXX账号激活");
        builder.setSmallIcon(android.R.drawable.star_on);//设置通知的图片
        builder.setDefaults(NotificationCompat.DEFAULT_ALL);
        builder.setAutoCancel(true);
//      builder.setContentIntent()
//        builder.setCustomContentView()
        Notification notification=builder.build();

        //发送通知
        notificationManager.notify(0x101,notification);
    }

上述代码就可以实现啦

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值