1. Download our Official Android App: Forums for Android!

Apps How to repeat the alarm for between 1 to 60 days at a particular time ?

Discussion in 'Android Development' started by Arthur Andy, Sep 15, 2011.

  1. Arthur Andy

    Arthur Andy Newbie
    Thread Starter
    Rank:
    None
    Points:
    16
    Posts:
    27
    Joined:
    Jul 5, 2011

    Jul 5, 2011
    27
    2
    16
    Hi,
    I have to repeat alarm for between 1 day to 60 days. For example, the user can be able to repeat alarm after every 5 days, 10 days or 60 days (maximum).

    Option1 ( Implemented Code:)
    -----------------------------
    alarmmanager.setRepeating(AlarmManager.RTC_WAKEUP, System.currentTimeMillis()+ (durationInDays * 24 * 3600 * 1000), (durationInDays * 24 * 3600 * 1000), pIntent);

    Note: But it is working fine but it supports maximum 10 days(appx) repeating only after that "(durationInDays * 24 * 3600 * 1000)" it goes into -ve value so, I am unable to set maximum 60 days alarm repeatedly. AlarmManager class only supports a long value for choosing the interval between the execution of the pending intent.

    Is there any other option to set repeat alarm for the no of days ?


    Option 2 ( Implemented Code:):
    -------------------------------
    Date futureDate = new Date(new Date().getTime() + (86400000 * durationInDays));
    Date dateInterval = new Date(86400000 * durationInDays);
    am.setRepeating(AlarmManager.RTC_WAKEUP, futureDate.getTime(), dateInterval.getTime(), pendingIntent);

    Note: We set repeating alarm maximum every 24 days but when i give (durationInDays = 25; // in Days) then it takes -ve values.

    Can I set repeating alarm with the help of Calender?

    Please help me by piece of code.


    Thanks in Advance,
    Andy
     

    Advertisement

  2. Arthur Andy

    Arthur Andy Newbie
    Thread Starter
    Rank:
    None
    Points:
    16
    Posts:
    27
    Joined:
    Jul 5, 2011

    Jul 5, 2011
    27
    2
    16
    Hi,
    I got one example regarding set alarm event using calendar.


    =======================================================
    Button clickMe = (Button) findViewById(R.id.set_event);
    clickMe.setOnClickListener(new OnClickListener() {

    @Override
    public void onClick(View v) {
    Cursor cursor = getContentResolver().query(Uri.parse("content://calendar/calendars"),
    new String[] { "_id", "displayName" }, "selected=1", null, null);
    if (cursor != null && cursor.moveToFirst()) {
    String[] calNames = new String[cursor.getCount()];
    int[] calIds = new int[cursor.getCount()];
    for (int i = 0; i < calNames.length; i++) {
    // retrieve the calendar names and ids
    calIds = cursor.getInt(0);
    calNames = cursor.getString(1);
    cursor.moveToNext();
    }
    cursor.close();
    if (calIds.length > 0) {
    // further work
    }
    // note the URI
    ContentValues event = new ContentValues();
    int cal_id = calIds[0];
    event.put("calendar_id", cal_id);
    event.put("title", "Event Demo");
    event.put("description", "Wedding party");
    event.put("eventLocation", "New York");
    event.put("eventStatus", 1);
    event.put("visibility", 0);
    event.put("transparency", 0);
    event.put("hasAlarm", 1);


    Calendar cal = new GregorianCalendar(TimeZone.getTimeZone("GMT"));

    Date dd = new Date("2011/02/17 05:07:00");
    cal.set(111 + 1900, 01, 25, 12, 30, 00);

    event.put("dtstart", cal.getTimeInMillis());
    Calendar endCal = new GregorianCalendar(TimeZone.getTimeZone("GMT"));
    endCal.set(111 + 1900, 01, 25, 18, 30, 00);
    event.put("dtend", endCal.getTimeInMillis());

    Uri eventsUri = Uri.parse("content://calendar/events");
    Uri url = getContentResolver().insert(eventsUri, event);
    }


    }
    });
    =======================================================

    It is working fine I am able to add event into Calendar event list. But Notification or alarm is not coming on that set time but only it show ur event was added into Calendar event list.

    "I can check the set event into device Calendar."

    Please help where I am doing mistake by piece of Codes. I am still waiting for your response.


    Thanks,
    Andy
     

Share This Page

Loading...