I want to make a notification to appear on a specific date at a specific time, as I wrote in the title. Now my alerts come in 10 seconds after pressing the button. If I need to set a specific date, do I need to do that as well? I need convert the date into milliseconds and give this parameter? Here's my code:
package com.example.timeman;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import androidx.core.app.NotificationCompat;
import androidx.core.app.NotificationManagerCompat;
public class ReminderBroadcast extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
NotificationCompat.Builder builder = new NotificationCompat.Builder(context, "notify")
.setSmallIcon(R.drawable.ic_baseline_close_24)
.setContentTitle("Salamabuliy")
.setContentText("TextNotif")
.setPriority(NotificationCompat.PRIORITY_DEFAULT)
;
NotificationManagerCompat notificationManager = NotificationManagerCompat.from(context);
notificationManager.notify(200, builder.build());
}
}
And OnClick Method:
public void onClick(View view) {
Intent intent = new Intent(getActivity(), ReminderBroadcast.class);
PendingIntent pendingIntent = PendingIntent.getBroadcast(getActivity(), 0, intent, 0);
AlarmManager alarmManager = (AlarmManager) getActivity().getSystemService(Context.ALARM_SERVICE);
long timeAtButtonClick = System.currentTimeMillis();
long tenSecondsInMillis = 1000*10;
alarmManager.set(AlarmManager.RTC, timeAtButtonClick + tenSecondsInMillis, pendingIntent);
//displayNotification();
OpenThis(view);
}