2

In my Application I have Multiple events for every event I need to create one UILocalNotification for example like I want to say wishes on Fathers day,Mothers and some festivals. So I already I have the specific date now I want to fire it on the particular day please how to do this. I have already done for single UILocalNotification. Now I need for multiple fire dates.

If I comment the date it's firing on particular time. Now date with time is not working. Now problem how to add multiple dates and time in same activity I want to fire the notifications.

Can anyone please help me.

MyView class

public class MyView extends Activity {

    /** Called when the activity is first created. */

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);


         Calendar firingCal = Calendar.getInstance();
            firingCal.set(Calendar.MONTH, 7);
             firingCal.set(Calendar.YEAR, 2014);
           firingCal.set(Calendar.DAY_OF_MONTH, 9);

           firingCal.set(Calendar.HOUR_OF_DAY, 16);
            firingCal.set(Calendar.MINUTE, 35);
            firingCal.set(Calendar.SECOND, 0);




        // MyView is my current Activity, and AlarmReceiver is the
        // BoradCastReceiver
        Intent myIntent = new Intent(MyView.this, AlarmReceiver.class);

        PendingIntent pendingIntent = PendingIntent.getBroadcast(MyView.this,
                0, myIntent, 0);

        AlarmManager alarmManager = (AlarmManager) getSystemService(ALARM_SERVICE);

        /*
         * The following sets the Alarm in the specific time by getting the long
         * value of the alarm date time which is in calendar object by calling
         * the getTimeInMillis(). Since Alarm supports only long value , we're
         * using this method.
         */

        alarmManager.set(AlarmManager.RTC_WAKEUP, firingCal.getTimeInMillis(),
                pendingIntent);
    }
}

MyAlarmService class

public class MyAlarmService extends Service 

{
     private NotificationManager mManager;

     @Override
     public IBinder onBind(Intent arg0)
     {
       // TODO Auto-generated method stub
        return null;
     }

    @Override
    public void onCreate() 
    {
       // TODO Auto-generated method stub  
       super.onCreate();
    }

   @SuppressWarnings("static-access")
   @Override
   public void onStart(Intent intent, int startId)
   {
       super.onStart(intent, startId);

       mManager = (NotificationManager) this.getApplicationContext().getSystemService(this.getApplicationContext().NOTIFICATION_SERVICE);
       Intent intent1 = new Intent(this.getApplicationContext(),MainActivity.class);

       Notification notification = new Notification(R.drawable.ic_launcher,"This is a test message!", System.currentTimeMillis());

       intent1.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP| Intent.FLAG_ACTIVITY_CLEAR_TOP);

       PendingIntent pendingNotificationIntent = PendingIntent.getActivity( this.getApplicationContext(),0, intent1,PendingIntent.FLAG_UPDATE_CURRENT);
       notification.flags |= Notification.FLAG_AUTO_CANCEL;
       notification.setLatestEventInfo(this.getApplicationContext(), "AlarmManagerDemo", "This is a test message!", pendingNotificationIntent);

       mManager.notify(0, notification);
    }

    @Override
    public void onDestroy() 
    {
        // TODO Auto-generated method stub
        super.onDestroy();
    }

}
madhan kumar
  • 1,560
  • 2
  • 26
  • 36
user3640092
  • 47
  • 1
  • 7

0 Answers0