zoukankan      html  css  js  c++  java
  • Notification中使用Glide

    之前一直在琢磨Glide自定义使用中的一些经验;今天简单的分享下Notification中使用Glide去加载icon方法;

         我们都知道使用android通知时,一般可能会有如下代码:

    NotificationCompat.Builder mBuilder =  
        new NotificationCompat.Builder(context)
            .setSmallIcon(R.mipmap.future_studio_launcher)
            .setContentTitle("Title")
            .setContentText("Text")
            .setContent(cView)//这里是你定义布局产生的对象
            .setPriority( NotificationCompat.PRIORITY_MIN);
    
    final Notification notification = mBuilder.build();
    NotificationManager mNotificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);  
    mNotificationManager.notify(xxxxx, notification);//Notification的使用是需要系统服务支持的,而且还需要你提供一个id=xxxxx

         到了Glide设置notification时又变成了极其简单的操作,代码如下:

    NotificationTarget notificationTarget = new NotificationTarget(context,
        cView,//通知展示的xml对象实例
        R.id.ImageView_notification_icon,//布局中ImageView的id
        notification,//通知的对象实例
        xxxxx);//通知的对象实例对应的id

         之后直接调用into插入NotificationTarget对象即可:

    Glide  
        .with( context)
        .load( eatFoodyImages[3] )
        .asBitmap()
        .into( notificationTarget );
  • 相关阅读:
    java对象序列化机制
    进程和线程的区别
    关于Java中的String类的不可变
    计算机编码ASCII、UNICODE和UTF-8
    mybatis中的一级缓存和二级缓存
    SQL语句之EXSITS谓词
    git学习笔记
    hdu1542-扫描线求矩形面积并
    首场ACM总结——2019JXCPC(CCPC江西省省赛)
    hdu1199(离散化线段树)
  • 原文地址:https://www.cnblogs.com/zzq-include/p/6236405.html
Copyright © 2011-2022 走看看