Gouse Mohiddin
Gouse Mohiddin

Reputation: 41

how to remove time counter from notification?

How to remove 'now' and the drop-down arrow from notification layout in my app. I am using a single layout for notification and yet it is expanding. I kept the height to 64dp and 50dp but no change in the size

    // Get the layouts to use in the custom notification
    RemoteViews notificationLayout = new RemoteViews(getPackageName(), R.layout.notification_small);
    //RemoteViews notificationLayoutExpanded = new RemoteViews(getPackageName(), R.layout.notification_large);
    notificationLayout.setTextViewText(R.id.otpText,otp);
    // Apply the layouts to the notification
    NotificationCompat.Builder builder = new NotificationCompat.Builder(getApplicationContext());
    builder.setSmallIcon(R.drawable.ic_launcher_foreground)
            .setStyle(new NotificationCompat.DecoratedCustomViewStyle())
            .setCustomContentView(notificationLayout)
            .setPriority(PRIORITY_MAX)
            .setDefaults(DEFAULT_SOUND)
            .setColor(getResources().getColor(R.color.colorAccent))
            .setDefaults(DEFAULT_VIBRATE)
            .setContentIntent(pendingIntent);

See this image of Android notifications

Upvotes: 3

Views: 987

Answers (2)

Abhi
Abhi

Reputation: 3511

According to the Documentation you can use:

setWhen(long when)
setShowWhen(boolean show);

By default setShowWhen is true, so you can set it to setShowWhen(false) to remove the timestamp.

Upvotes: 2

Jerome
Jerome

Reputation: 1281

just use

builder.setSmallIcon(R.drawable.ic_launcher_foreground)
...
       .setWhen(0)
...

Upvotes: 1

Related Questions