0

I am trying to use the calendar to create notifications using the alarm manager. The problem I am having is that the alarm does not "go off" at the time I set using the calendar.

Code:

// Removed imports

public class RemDateFragment extends Fragment implements OnClickListener{

    DatePicker datePicker;

    Integer day;
    Integer month;
    Integer year;

    // Removed stuff including button, onclicklistener etc

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
            Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        View RemDate = inflater.inflate(R.layout.rem_date_fragment, container, false);
        datePicker = (DatePicker) RemDate.findViewById(R.id.rd_dp);

        return RemDate;
    }

    @Override
    public void onClick(View v) {

        switch (v.getId()) { // Notification doesn't work properly just yet

        case R.id.rd_b_create:

            day = datePicker.getDayOfMonth();
            month = datePicker.getMonth();
            year = datePicker.getYear();

            Calendar cal = Calendar.getInstance();  // Didn't work

            cal.set(Calendar.DAY_OF_MONTH, day);
            cal.set(Calendar.MONTH, month);
            cal.set(Calendar.YEAR, year);
            cal.set(Calendar.HOUR_OF_DAY, 9);


            int vDay = day.intValue();
            int vMonth = month.intValue();
            int vYear = year.intValue();


            if (content_title.length() >=1) {

                  Intent remIntent = new Intent();
                  remIntent.setAction("com.RiThBo.noter.remBroadcast");
                  Bundle extras = new Bundle();
                     extras.putString("content_title", (String)content_title);  
                     extras.putString("content_text", (String)content_text);  
                     extras.putBoolean("bOngoing", boolean_ongoing);
                     remIntent.putExtras(extras);  
                  sendBroadcast(remIntent); 

                PendingIntent remPendingIntent =  PendingIntent.getBroadcast(
                        this.getActivity(), 0, remIntent, 0);

                getActivity();
                AlarmManager remAlarmManager = (AlarmManager) getActivity().getSystemService(Context.ALARM_SERVICE); // The "Context" refers to the "getActivity" in the line above
                remAlarmManager.set(AlarmManager.RTC_WAKEUP, cal.getTimeInMillis(), remPendingIntent); // Instead of 'sleeping' as i was going to do, add the input time to the system current time
                Toast.makeText(getActivity(), "Set for " + vDay + "/" + vMonth + "/" + vYear, Toast.LENGTH_SHORT).show(); // Showing that the values are being set correctly

            }
        }


}

    private void sendBroadcast(Intent remIntent) {
        // TODO Auto-generated method stub
    }
    }

The broadcast just creates a notification. This works fine with my other fragments so don't think that is the problem.

Thank you

  • May be this [Link][1] [1]: http://stackoverflow.com/questions/14598063/reminder-functionality will help you. – Manoj Fegde Jun 28 '13 at 10:34
  • ( sorry been away) Thank you, will see in a bit –  Jun 28 '13 at 17:26
  • @ManojFegde Thank you for the link but it seems very similar to the way I had used - but mine is not working. Ninth hour in java is "nine o clock" isnt it? :-) –  Jun 28 '13 at 19:24
  • Okaay... Apparently it works now!! Maybe I wasn't testing properly :-) Thank you for the answer ( it was helpful anyway) and sorry for the wasted question –  Jun 28 '13 at 19:30

0 Answers0