1

I am trying to build custom notification for my app, but I am not able to remove the header information (which includes small icon, app name, time) and the expand icon. Basically I want completely my own design of notification which takes full width and height.

private void createNotification() {
    // BEGIN_INCLUDE(notificationCompat)
    NotificationCompat.Builder builder = new NotificationCompat.Builder(this, NOTIFICATION_CHANNEL);

    Intent i = new Intent(this, MainActivity.class);
    i.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
    PendingIntent intent = PendingIntent.getActivity(this, 0, i,
            PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_IMMUTABLE);
    builder.setContentIntent(intent);

    builder.setSmallIcon(R.drawable.ic_stat_custom);
    builder.setAutoCancel(true);

    RemoteViews contentView = new RemoteViews(getPackageName(), R.layout.notification);

    // Set text on a TextView in the RemoteViews programmatically.
    final String time = DateFormat.getTimeInstance().format(new Date()).toString();
    final String text = getResources().getString(R.string.collapsed, time);
    contentView.setTextViewText(R.id.textView, text);

    builder.setCustomContentView(contentView);

    if (Build.VERSION.SDK_INT >= 16) {
        // Inflate and set the layout for the expanded notification view
        RemoteViews expandedView =
                new RemoteViews(getPackageName(), R.layout.notification_expanded);
        builder.setCustomBigContentView(expandedView);
    }


    Notification notification = builder.build();

    NotificationManager nm = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
    nm.notify(0, notification);
}

I am getting this as output:

But I want this notification as:

Is there anyway to achieve this?

koder
  • 454
  • 6
  • 18
  • You are using OS default notifications. header will be added so, If you need to achieve your UI search for implementing custom notification not os defaults. – Hamid Reza Nov 26 '22 at 09:02
  • This is a custom notification. I am using these two methods setCustomContentView and setCustomBigContentView to set custom UI. – koder Nov 26 '22 at 10:08
  • 1
    @koder Are you testing your app on android 12 or above? If so, have a look at this https://developer.android.com/about/versions/12/behavior-changes-12#custom-notifications – Javlon Nov 26 '22 at 10:18

1 Answers1

1

u can easily add

.setSmallIcon(android.R.color.transparent) 

or create custom notification, check this doc out: https://developer.android.com/develop/ui/views/notifications/custom-notification

also this is an article about custom notification:
https://medium.com/hootsuite-engineering/custom-notifications-for-android-ac10ca67a08c

Mahdi Razzaghi
  • 185
  • 2
  • 10