Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how can i set time and date for notification

in the notification manager we use this method to set time and date to fire notification

.setWhen(System.currentTimeMillis());

but the System.currentTimeMillis() get back the current time on device but i want to add specified time like ( Friday 15:00 )

how can i do that ?? how can i set this time in milliseconds and load it up in .setWhen

thanks in advance

this code i use

Notification.Builder builder =
new Notification.Builder(MyActivity.this);
builder.setSmallIcon(R.drawable.ic_launcher)
.setTicker(“Notification”)
.setWhen(System.currentTimeMillis())
.setDefaults(Notification.DEFAULT_SOUND |
Notification.DEFAULT_VIBRATE)
.setSound(
RingtoneManager.getDefaultUri(
RingtoneManager.TYPE_NOTIFICATION))
.setVibrate(new long[] { 1000, 1000, 1000, 1000, 1000 })
.setLights(Color.RED, 0, 1);
Notification notification = builder.getNotification();
like image 249
eng.ahmed Avatar asked Mar 17 '13 07:03

eng.ahmed


People also ask

How do I see time on Android notifications?

currentTimeMillis() should update the timestamp to the current time. In addition if you want that timestamp to appear on Android N or higher, you need to call NotificationCompat. Builder#setShowWhen(true) at some point because it defaults to false. Save this answer.


1 Answers

You should use the Java Calendar class to specify a date. Instantiate a Calendar object using the getInstance() factory method. By default, the instance will be initialized with the current date and time for the default time zone of your machine. Calendar contains different set() methods to specify a date, choose one that's more appropriate for your needs and use it to specify the date you need. Then call the getTimeInMillis() method, which will return specified date in milliseconds. Hope this helps.

like image 67
Egor Avatar answered Sep 19 '22 07:09

Egor