2

In my app I need to schedule multiple notifications on a particular day and in different time intervals.(e.g: on 3/12/2015 at 9AM,11AM,2PM,5PM I need to show notifications with different content).

I have used Alarm Manager and Broadcast Receiver to show these There are some problems I'm facing

  1. I can show only one notification when I'm using calander object to set date.
  2. When I click on Notification its opening the App and notification is firing again.
  3. Notification is shown only when App is opened.

This is my MainActivity.java

 AlarmManager alarmManager = (AlarmManager) getSystemService(Context.ALARM_SERVICE);

    Intent notificationIntent = new Intent("android.media.action.DISPLAY_NOTIFICATION");
    notificationIntent.addCategory("android.intent.category.DEFAULT");

    PendingIntent broadcast = PendingIntent.getBroadcast(this, 100, notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT);

    Calendar cal = Calendar.getInstance();
    cal.set(2015, 11, 1, 12, 47);
    cal.set(2015, 11, 1, 12, 53);
    alarmManager.setExact(AlarmManager.RTC_WAKEUP, cal.getTimeInMillis(), broadcast);

This is my BroadCastReceiver

Intent notificationIntent = new Intent(context, MainActivity.class);

    TaskStackBuilder stackBuilder = TaskStackBuilder.create(context);
    stackBuilder.addParentStack(MainActivity.class);
    stackBuilder.addNextIntent(notificationIntent);

    PendingIntent pendingIntent1 = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);

    NotificationCompat.Builder builder = new NotificationCompat.Builder(context);

    Notification notification = builder.setContentTitle("TRR - 2016")
            .setContentText("Station - 1 closed grace period only 10min")
            .setTicker("New Message Alert!")
            .setSmallIcon(R.mipmap.ic_launcher)
            .setAutoCancel(true)
            .setContentIntent(pendingIntent1).build();

    NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
    notification.defaults |= Notification.DEFAULT_LIGHTS;
    notification.defaults |= Notification.DEFAULT_VIBRATE;
    notification.defaults |= Notification.DEFAULT_SOUND;

    notification.flags |= Notification.FLAG_ONLY_ALERT_ONCE;
    notificationManager.notify(++mCounter, notification);

Please Help me to solve this.

ShivLeela
  • 117
  • 1
  • 3
  • 12

0 Answers0