Search code examples
androidcalendarbroadcastreceiveralarmmanagerlocalnotification

how to set alarmmanager for local notification?


Here is my code for set alarm and getting notification :-

Calendar calendar = Calendar.getInstance();
calendar.set(Calendar.MONTH, Integer.parseInt("2"));
calendar.set(Calendar.YEAR, Integer.parseInt("2016"));
calendar.set(Calendar.DAY_OF_MONTH, Integer.parseInt("20"));

calendar.set(Calendar.HOUR_OF_DAY, Integer.parseInt("11"));
calendar.set(Calendar.MINUTE, Integer.parseInt("50"));

Intent myIntent = new Intent(getActivity(), MyReceiver.class);
pendingIntent = PendingIntent.getBroadcast(getActivity(), 0, myIntent,
                     PendingIntent.FLAG_UPDATE_CURRENT);

AlarmManager alarmManager = (AlarmManager)getActivity().getSystemService(getActivity().ALARM_SERVICE);
Log.v("Time:", calendar.getTimeInMillis() + "");
alarmManager.set(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), pendingIntent);

register receiver in manifest file but not call receiver.

if i change calendar.getTimeInMillis() to System.currentTimeMillis(); then code is working

but this code not working any one have idea to fire notification from alaram manager then help me.

Thanks in advance.


Solution

  • You try to send noty in the future. "2" is not february it's march