【问题标题】:How to set custom notification icons from URL image Nougat and above OS Version?如何从 URL 图像 Nougat 及以上操作系统版本设置自定义通知图标?
【发布时间】:2018-03-02 11:44:26
【问题描述】:

我已经在通知中通过图像 URL 实现了自定义图标,这是通过使用以下代码获取默认远程视图来实现的

RemoteViews contentView = notification.contentView;
                RemoteViews bigContentView = notification.bigContentView;
                int bigIconId = context.getResources().getIdentifier("android:id/big_picture", null, null);
                int iconId = context.getResources().getIdentifier("android:id/icon", null, null);
                int smallIconId = context.getResources().getIdentifier("right_icon", "id", android.R.class.getPackage().getName());
                int largeIconExId = context.getResources().getIdentifier("profile_badge", "id", android.R.class.getPackage().getName());
                if (finalSmallIcon != null)
                    Picasso.with(context).load(finalSmallIcon).into(contentView, iconId, finalData_id, notification);
                if (finalLargeIcon != null) {
                    Picasso.with(context).load(finalLargeIcon).into(contentView, iconId, finalData_id, notification);
                    Picasso.with(context).load(finalLargeIcon).into(contentView, largeIconExId, finalData_id, notification);
                }
                if (finalSmallIcon != null)
                    Picasso.with(context).load(finalSmallIcon).into(contentView, smallIconId, finalData_id, notification);

                if (finalBigPicture != null) {
                    //  Picasso.with(context).load(finalLargeIcon).into(bigContentView, iconId, finalData_id, notification);
                    Picasso.with(context).load(finalBigPicture).into(bigContentView, bigIconId, finalData_id, notification);
                }
            }
        });

但在 Nougat 及更高版本中,从“notification.contentView”中获取 null。那么如何使用 customLayout 和 RemoteView 类更新 Nougat 及更高版本中的通知图标。 提前致谢。

【问题讨论】:

    标签: java android android-layout android-notifications custom-notification


    【解决方案1】:
        NotificationCompat.Builder notificationBuilder = new notificationCompat.Builder(context);
            notificationBuilder
                    .setSmallIcon(context.getApplicationInfo().icon);
            notificationBuilder.setLargeIcon(largeIcon != null &&!largeIcon.isEmpty()? Picasso.with(context).load(largeIcon).get() : BitmapFactory.decodeResource(context.getResources(), R.mipmap.ic_launcher));
    

    【讨论】:

      猜你喜欢
      • 2020-02-15
      • 1970-01-01
      • 1970-01-01
      • 2018-08-20
      • 2021-09-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多