Android Notificatin 通知

通知的简单使用

1-通知渠道:android 8.0 必须设置通知渠道,否则通知不会显示。
2-通知图标问题:android 5.0 谷歌为了统一风格,统一使用背景为透明的图标,否则显示一个白色图标。如图
在这里插入图片描述

    // 获取通知的管理器
        NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);

        // android 8.0  以上才有 通知渠道
        if (Build.VERSION.SDK_INT>= 26){

            NotificationChannel notificationChannel = new NotificationChannel("id", "unKnowName", NotificationManager.IMPORTANCE_DEFAULT);

            // 设置灯的颜色
            notificationChannel.setLightColor(Color.RED);
//            开启呼吸灯
            notificationChannel.enableLights(true);
            // 设置角标
//            notificationChannel.setShowBadge(true);
            notificationChannel.setDescription("这是渠道描述");


            notificationManager.createNotificationChannel(notificationChannel);
        }

        Intent intent = new Intent(this, MainActivity2.class);
        // 延时意图
        PendingIntent pendingIntent = PendingIntent.getActivity(this, 11, intent, PendingIntent.FLAG_UPDATE_CURRENT);

        // 创建通知对象
        Notification notification = new NotificationCompat.Builder(this, "id")

                .setSmallIcon(R.drawable.zfb)
                .setContentTitle("HHHHHHHHHHH")
                .setContentText("GGGGGGGGGGGGGGGGGGGGG")
                .setContentIntent(pendingIntent)
                .setAutoCancel(true)
                .build();


        // 发送通知对象
        notificationManager.notify(111,notification);
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值