How to set the date format for advanced notification

If I have a new message, only the time is displayed in the advanced notification view. Suppose that if I received a message today (that is 06.06.2010), it should simply display the line "Today", and tomorrow it should show the date on the message whilch, that is, the date 06/06/2010 should be displayed

+3
source share
2 answers

You need to write a custom object DateFormatand then callDateFormat.format(Date)

0
source

If you have a date in milliseconds, for example,

long myDate = Calendar.getInstance().getTimeInMillis();

Otherwise, you can get an instance of calander and setTime

SimpleDateFormat sdf = new SimpleDateFormat();
sdf.applyPattern("MM/dd/yyyy");
Calendar calendar = Calendar.getInstance();
Date processDate = sdf.parse("4/10/2007″);
calendar.setTime(processDate);
long myDate = calendar.getTimeInMillis();

Then you can distinguish between date and system date.

String dateMessage = "today";
final int dayInterval = 86400000;
long difference = Calendar.getInstance().getTimeInMillis() - myDateInMillis;
if (difference > dayInterval)
    //dateMessage = format date MM/DD/YYYY...

, . . .

. . TextViews Remoteview. , .

RemoteViews contentView = new RemoteViews(getPackageName(), R.layout.custom_notification);
contentView.setTextViewText(R.id.text, mTitle);

, .

0

Source: https://habr.com/ru/post/1748711/


All Articles