Answer the question
In order to leave comments, you need to log in
Why is the notification coming early?
private Runnable Timer = new Runnable() {
@Override
public void run() {
try {
Thread.sleep(1000);
} catch (Throwable t) {
}
};
};
Based on this thread, I created a kind of timer
while (LAST_MILLI_SEC != 0);{
new Thread(Timer).start();
String t = String.valueOf((LAST_MILLI_SEC/1000)-1);
Toast.makeText(this, t,Toast.LENGTH_LONG).show();//After every sec. sleep outputs the message
LAST_MILLI_SEC = LAST_MILLI_SEC - 1000;//Then subtracts 1 second from the remaining time
if(LAST_MILLI_SEC/1000 == 0){
//Here, the timer must first count down to zero, and only then send a notification?????
Notification notification = new Notification();
Context context = getApplicationContext();
Intent notificationIntent = new Intent(context, MainActivity.class);
PendingIntent pIntent = PendingIntent.getActivity(context, 0,
notificationIntent, Intent.FLAG_ACTIVITY_NEW_TASK);
long[] vibrate = new long[] {1000, 1000, 1000, 1000, 1000};
notificationIntent.putExtra("url", "dtrek.dp.ua");
Notification.Builder builder = new Notification.Builder(context)
.setContentTitle("Look at the replacements")
.setTicker("Warning!") // java.lang.System.currentTimeMillis()
.setContentIntent(pIntent)
.setDefaults(Notification.DEFAULT_SOUND).setAutoCancel(true)
.setSmallIcon(R.drawable.ic_launcher);
NotificationManager nm = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
nm.notify(NOTIFY_ID, builder.build());
notification.vibrate = vibrate;
notification.flags = notification.flags | Notification.FLAG_INSISTENT; }
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question