I am trying to make a simple function that schedules local notifications in Android but it doesn't work. Am I missing something? i. e. a permission in the manifest or something like that? I am pretty newbie to android programming.
static int notificationId = 0;
public void scheduleLocalNotification(String text, int seconds)
{
Context context = getApplicationContext();
long when = System.currentTimeMillis() + seconds * 1000;
NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
Intent notificationIntent = new Intent(context, MyApp.class);
// set intent so it does not start a new activity
notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP
| Intent.FLAG_ACTIVITY_SINGLE_TOP);
PendingIntent intent = PendingIntent.getActivity(context, 0,
notificationIntent, 0);
Notification notification = new Notification();
notification.setLatestEventInfo(context, "My application", text, intent);
notification.flags |= Notification.FLAG_AUTO_CANCEL;
notification.when = when;
notificationManager.notify(notificationId, notification);
notificationId ++;
}