Как установить будильник перед указанием c времени в android студии? - PullRequest
0 голосов
/ 15 апреля 2020

Мои коды

calendar = Calendar.getInstance();
    calendar.set(Calendar.MONTH, month);
    calendar.set(Calendar.YEAR, year);
    calendar.set(Calendar.DAY_OF_MONTH, date);

    long eventTime=calendar.getTimeInMillis();

    long oneDay=AlarmManager.INTERVAL_DAY;
    int noOfDays=4;
    long reminderTime=eventTime-(noOfDays*oneDay);

    Intent myIntent = new Intent(Home.this, MyBroadcast.class);
    PendingIntent pendingIntent = PendingIntent.getBroadcast(Home.this, 0, myIntent,0);
    AlarmManager alarmManager = (AlarmManager)getSystemService(ALARM_SERVICE);
    alarmManager.set(AlarmManager.RTC_WAKEUP, reminderTime, pendingIntent);

Я попробовал все, но он будет звонить прямо при установке!

1 Ответ

0 голосов
/ 15 апреля 2020

Вам необходимо использовать григорианский календарь,

Gregorian calender Calendar cur_cal = new GregorianCalendar();
cur_cal.setTimeInMillis(System.currentTimeMillis());
...