首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何设置自定义通知图标从URL图片努gat和以上的操作系统版本?

如何设置自定义通知图标从URL图片努gat和以上的操作系统版本?
EN

Stack Overflow用户
提问于 2018-03-02 11:44:26
回答 1查看 682关注 0票数 1

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

代码语言:javascript
复制
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);
                }
            }
        });

但在努格特及以上,从"notification.contentView“中获得null。那么,如何使用customLayout和RemoteView类更新努格特及以上版本中的通知图标。提前谢谢。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2018-07-20 11:02:01

代码语言:javascript
复制
    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));
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/49068449

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档