Try something like:
@SuppressLint("NewApi")
public static void showNotification(Context context, String message) {
Intent intent = new Intent(context, MainActivity.class);
// Ensures navigating back to activity, then to Home screen.
TaskStackBuilder stackBuilder = TaskStackBuilder.create(context);
// Add the activity parent chain to the stack builder.
stackBuilder.addParentStack(MainActivity.class);
// Add a new Intent to the task stack.
stackBuilder.addNextIntent(intent);
PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
// Create notification.
if (Build.VERSION.SDK_INT > Build.VERSION_CODES.ICE_CREAM_SANDWICH_MR1) {
// API 16 onwards.
Notification.Builder builder = new Notification.Builder(context)
.setAutoCancel(true)
.setContentIntent(pendingIntent)
.setContentTitle(context.getString(R.string.app_name))
.setSmallIcon(R.drawable.ic_notifier)
.setTicker(message)
.setContentText(message)
.setPriority(Notification.PRIORITY_HIGH)
.setStyle(new Notification.BigTextStyle().bigText(message))
.setWhen(System.currentTimeMillis());
mNotificationManager.notify(NOTIFICATION_DEFAULT, builder.build());
} else {
// API 15 and earlier.
NotificationCompat.Builder builder = new NotificationCompat.Builder(context)
.setAutoCancel(true)
.setContentIntent(pendingIntent)
.setContentTitle(context.getString(R.string.app_name))
.setSmallIcon(R.drawable.ic_notifier)
.setTicker(message)
.setContentText(message)
.setPriority(Notification.PRIORITY_HIGH)
.setWhen(System.currentTimeMillis());
mNotificationManager.notify(NOTIFICATION_DEFAULT, builder.build());
}
}