Skip to content

Instantly share code, notes, and snippets.

@Marchuck
Created January 2, 2019 15:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Marchuck/1b00ab79a430f950d928838b0500225a to your computer and use it in GitHub Desktop.
Save Marchuck/1b00ab79a430f950d928838b0500225a to your computer and use it in GitHub Desktop.
class Foo {
public void showNotification(String _subText,
String _bigContentTitle,
String _bigText) {
String channelId = "channelId";
NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(context, channelId);
notificationBuilder.setAutoCancel(true);
Intent intent = new Intent(context.getApplicationContext(), YourActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP);
PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
NotificationCompat.BigTextStyle bigNotificationStyle = new NotificationCompat.BigTextStyle();
bigNotificationStyle.bigText(_bigText);
bigNotificationStyle.setBigContentTitle(_bigContentTitle);
notificationBuilder.setContentIntent(pendingIntent);
notificationBuilder.setSmallIcon(R.mipmap.ic_launcher);
notificationBuilder.setSubText(_subText);
notificationBuilder.setPriority(Notification.PRIORITY_MAX);
notificationBuilder.setStyle(
new NotificationCompat.BigPictureStyle()
.bigPicture(BitmapFactory.decodeResource(context.getResources(), R.drawable.ic_receive))
.setBigContentTitle(_bigContentTitle)
.bigLargeIcon(null)
);
NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
NotificationChannel channel = new NotificationChannel(channelId, channelId, NotificationManager.IMPORTANCE_HIGH);
if (notificationManager != null) {
notificationManager.createNotificationChannel(channel);
}
}
if (notificationManager != null) {
notificationManager.notify(0, notificationBuilder.build());
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment