Question

I want to display a notification for the users of my app every day at a specific time. Maybe at 1pm. So how do I do this? I know, with an AlarmManager or Calender. But how?

 NotificationCompat.Builder mBuilder =
            new NotificationCompat.Builder(this)
                    .setSmallIcon(R.drawable.ic_launcher)
                    .setContentTitle("TEST")
                    .setContentText("Benachrichtigung");
    Intent resultIntent = new Intent(this, MainActivity.class);
    TaskStackBuilder stackBuilder = TaskStackBuilder.create(this);
    stackBuilder.addParentStack(MainActivity.class);
    stackBuilder.addNextIntent(resultIntent);
    PendingIntent resultPendingIntent =
            stackBuilder.getPendingIntent(
                    0,
                    PendingIntent.FLAG_UPDATE_CURRENT
            );
    mBuilder.setContentIntent(resultPendingIntent);
    NotificationManager mNotificationManager =
            (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
    mNotificationManager.notify(123, mBuilder.build());

Thanks!

Was it helpful?

Solution

I've a sample app about the Alarm Manager. You can take a look it from here. What you need to do basically is, push notification whenever you receive an alarm in alarm receiver Broadcast Receiver.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top