美文网首页android疑难问题
Android Notificatin 通知

Android Notificatin 通知

作者: NullPoint3Exce | 来源:发表于2020-01-01 21:45 被阅读0次

通知的简单使用

1-通知渠道:android 8.0 必须设置通知渠道,否则通知不会显示。
2-通知图标问题:android 5.0 谷歌为了统一风格,统一使用背景为透明(经测试单色的图片也可以)的图标,否则显示一个白色图标。如图


image.png

3-使用背景色为透明的图片,最终效果为:


元素图 最终效果图

注意状态栏图片的颜色,还是白色,但是图片图案是正常的。
这是什么问题呢?查看源码,发现是官方故意做的。想了解的同学可以去查看官方代码,这里不做介绍。

4-普通的通知三要素:小图标 标题 内容

    // 获取通知的管理器
        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);

相关文章

  • Android Notificatin 通知

    通知的简单使用 1-通知渠道:android 8.0 必须设置通知渠道,否则通知不会显示。2-通知图标问题:and...

  • Android直接回复通知

    Android直接回复通知 通知直接回复 Android N/7.0 前言 通知(Notification)可为是...

  • 《Android第一行代码》first reading 十

    Android多媒体运用 一 通知 使用Android通知功能步骤: 通过Context的getSystemSer...

  • Android的通知

    通知是什么? 通知存在的意义是什么? Android O(Android SDK Api Level 26,And...

  • android通知

    1.这里写了一个常用的通知的代码

  • Android通知

    通知在实际开发中还是比较常见的,例如新闻,音乐播放器,等。 1,基本通知 2,基础扩展通知自定义布局 xml >>...

  • android 通知

    notification需要一个NotificationManager来管理,如何获取呢?Notification...

  • Android通知

    在这里写一个Android的通知,相应的图标以及位置大概也有介绍,需要的时候可以试试;

  • Android 通知

    Android 8.0中各种通知写法汇总https://www.jianshu.com/p/6aec3656e27...

  • Android:通知

    如果你将项目中的targetSdkVersion指定到了26或者更高(targetSdkVersion可以在app...

网友评论

    本文标题:Android Notificatin 通知

    本文链接:https://www.haomeiwen.com/subject/ngbgoctx.html