How do I set alarm before specific time in android studio? Code Answer

Hello Developer, Hope you guys are doing great. Today at Tutorial Guruji Official website, we are sharing the answer of How do I set alarm before specific time in android studio? without wasting too much if your time.

The question is published on by Tutorial Guruji team.

My codes

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);

I tried everything but It will ring right on I setting it !

Answer

You need to use Gregorian calendar,

Gregorian calender Calendar cur_cal = new GregorianCalendar();
cur_cal.setTimeInMillis(System.currentTimeMillis());
We are here to answer your question about How do I set alarm before specific time in android studio? - If you find the proper solution, please don't forgot to share this with your team members.

Related Posts

Tutorial Guruji