From PendingIntent to Notification

84 Views Asked by At

I try to display a notification each day at a given time, so I use the AlarmManager, which activates my PendingIntent. Now I'm trying to make this PendingIntent to show a notification. Any ideas on how I should make this work?

My code:

private AlarmManager alarmMgr;
private PendingIntent alarmIntent;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    check_products(7, 0);
    check_products(16, 0);
}

public void check_products(int hour, int minute){
    Calendar calendar = Calendar.getInstance();
    calendar.setTimeInMillis(System.currentTimeMillis());
    calendar.set(Calendar.HOUR_OF_DAY, hour);
    calendar.set(Calendar.MINUTE, minute);
    alarmMgr.setInexactRepeating(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), AlarmManager.INTERVAL_DAY, alarmIntent);
}
1

There are 1 best solutions below

3
On

you have to make a broadcast receiver for your task, as the given time meets requirement then generate a notification using PendingIntent...