• 自定义通知栏显示不全、heads-up通知栏的应用


    首先是自定义显示不全的问题,通常是设置removeview的方法不对
    通过builder.setContent(remoteViews);给通知添加自定义界面,结果由于自定义界面布局过高,底部界面被压缩显示。
    用.setCustomBigContentView(mRemoteViews)
    setContent 设置普通视图,高度限制为 64 dp
    setCustomContentView设置普通视图,高度限制为 64 dp
    setCustomBigContentView() 设置扩展视图,高度可以扩展到256dp
    setCustomHeadsUpContentView() 设置浮动通知视图

    悬浮通知栏的应用(heads-up):

          Intent intent = new Intent(context, MainActivity.class);
            PendingIntent pendingIntent = PendingIntent.getActivity(context, 100, intent, PendingIntent.FLAG_UPDATE_CURRENT);
            NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
            final NotificationCompat.Builder builder;
            builder = new NotificationCompat.Builder(context, HEAD_CHANEL_ID)
                    .setSmallIcon(R.mipmap.notification_small_icon)
                    .setContentIntent(pendingIntent)
                    .setCustomHeadsUpContentView(bigRemoteViews)
                    .setContent(remoteViews)
                    .setPriority(NotificationCompat.PRIORITY_MAX)
                    .setCategory(NotificationCompat.CATEGORY_CALL)
                    .setDefaults(android.app.Notification.DEFAULT_ALL)
                    .setAutoCancel(true)
                    // Use a full-screen intent only for the highest-priority alerts where you
                    // have an associated activity that you would like to launch after the user
                    // interacts with the notification. Also, if your app targets Android 10
                    // or higher, you need to request the USE_FULL_SCREEN_INTENT permission in
                    // order for the platform to invoke this notification.
                    .setFullScreenIntent(pendingIntent, true);
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
                NotificationChannel channel = new NotificationChannel(HEAD_CHANEL_ID, HEAD_CHANEL_NAME, NotificationManager.IMPORTANCE_MAX);
                notificationManager.createNotificationChannel(channel);
                builder.setChannelId(HEAD_CHANEL_ID);
                builder.setContentTitle(HEAD_CHANEL_NAME);
            }
            notificationManager.notify(BIG_INTERCEPTION, builder.build());
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26

    记得,不同功能的通知栏的channelid和name不要重复,否则会弹不出来,比如常驻和提示通知栏用了一个,因为常驻先出来了,所以提示通知栏就不展示…

    这里是用了32版本的代码,建议as升到Chipmunk以上使用,大家的代码还是要实时更新的呀~
    今天的分享就在这了~嘿嘿

  • 相关阅读:
    基于UNI-APP实现适配器并保证适配器和实现的调用一致
    剑指 Offer II 036. 后缀表达式
    Django日志集成 & MySQL/Redis 异常捕获
    职业:需求量最大的6个区块链工作
    前端Vue+后端Django实现微信登录
    Excel往Word复制表格时删除空格
    详解MES系统在质检管理中的多角度应用
    Django Cookie与Session
    LVS精益价值管理系统 LVS.Web.ashx SQL注入漏洞复现
    Pycharm 安装配置 pyQt5 图文操作(全)
  • 原文地址:https://blog.csdn.net/weixin_42405406/article/details/125501596