Load image from url in notification Android

前端 未结 8 801
北海茫月
北海茫月 2020-11-28 21:48

In my android application, i want to set Notification icons dynamically which will be loaded from URL. For that, i have used setLargeIcon property of Notificati

8条回答
  •  南方客
    南方客 (楼主)
    2020-11-28 22:24

    Using Picasso Library.

                   Target target = new Target() {
                        @Override
                        public void onBitmapLoaded(Bitmap bitmap, Picasso.LoadedFrom from) {
                            largeIcon=bitmap;
                        }
    
                        @Override
                        public void onBitmapFailed(Drawable errorDrawable) {
                        }
    
                        @Override
                        public void onPrepareLoad(Drawable placeHolderDrawable) {
                        }
                    };
    
                    Picasso.with(this).load("url").into(target); 
    
    
    
    
    
                   NotificationCompat.Builder notificationBuilder =
                        new NotificationCompat.Builder(this, channelId)
                                .setSmallIcon(R.drawable.icon)
                                .setContentTitle(msg.getString("title"))
                                .setContentText(msg.getString("msg"))
                                .setAutoCancel(true)
                                .setSound(defaultSoundUri)
                                .setLargeIcon(largeIcon)
                                .setContentIntent(pendingIntent);
    

提交回复
热议问题