Skip to content

Instantly share code, notes, and snippets.

@JChudasama
Last active May 24, 2023 09:04
Show Gist options
  • Save JChudasama/98b1bdbd06aa5c39480799cf0d50ae5c to your computer and use it in GitHub Desktop.
Save JChudasama/98b1bdbd06aa5c39480799cf0d50ae5c to your computer and use it in GitHub Desktop.
Android Image Notification Sample from URL (using Picasso) - Big Picture Style
final NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context)
.setContentTitle(context.getString(R.string.app_name))
.setSmallIcon(R.mipmap.ic_launcher)
.setContentText("notification with image")
.setContentIntent(resultPendingIntent)
.setPriority(Notification.PRIORITY_DEFAULT)
.setAutoCancel(true)
.setGroup(context.getString(R.string.app_name))
.setDefaults(defaults);
Picasso.with(context.getApplicationContext()).load("URL_OF_IMAGE").into(new Target() {
@Override
public void onBitmapLoaded(Bitmap bitmap, Picasso.LoadedFrom from) {
try {
NotificationCompat.BigPictureStyle s = new NotificationCompat.BigPictureStyle().bigPicture(bitmap);
s.setSummaryText("notification with image");
mBuilder.setStyle(s);
// firing notification here, will beep sound once,
NotificationManagerCompat mNotificationManager = NotificationManagerCompat.from(context);
Notification notificationCompat = mBuilder.build();
mNotificationManager.notify(199, notificationCompat);
}catch (Exception e){
e.printStackTrace();
}
}
@Override
public void onBitmapFailed(Drawable errorDrawable) {
// handle error here
}
@Override
public void onPrepareLoad(Drawable placeHolderDrawable) {
// place holder to set here
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment