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();
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With