Set time in Android Alarm Manager - instantly triggers an alarm

Possible duplicate:
Why does my Android Alarm Manager start instantly?

I have this code that will trigger an alert notification

public static  Calendar cal = Calendar.getInstance();
cal.setTimeInMillis(System.currentTimeMillis());
cal.add(Calendar.HOUR_OF_DAY,hour);
cal.add(Calendar.MINUTE, min);
Intent intent = new Intent(this,  OnetimeAlarmReceiver.class);
PendingIntent pendingIntent = PendingIntent.getBroadcast(this, REQUEST_CODE, intent,0);
AlarmManager alarmManager = (AlarmManager) getSystemService(ALARM_SERVICE);
alarmManager.set(AlarmManager.RTC_WAKEUP, cal.getTimeInMillis() , pendingIntent); 
Toast.makeText(this, "Alarm set", Toast.LENGTH_LONG).show();

but the alarm is triggered instantly, does the dispenser wait after a specified hour and minutes? Should I add anything to the manifest file?

+3
source share
1 answer

You are using the current time to set the alarm. Therefore, it works instantly.

API. http://developer.android.com/reference/android/app/AlarmManager.html#set%28int,%20long,%20android.app.PendingIntent%29

, . . , , , .

+3

Source: https://habr.com/ru/post/1771066/


All Articles