Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7663961
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T14:10:53+00:00 2026-05-31T14:10:53+00:00

I use the undocumented API’s for adding calendar event for Android OS 2.2. Now

  • 0

I use the undocumented API’s for adding calendar event for Android OS 2.2. Now Android OS 4 is out, naturally the API’s I used don’t work! I looked at the Android SDK regarding the calendar api’s in level 14 but I’d not able to found a clue how to use this in my project that I have created using Android OS 2.2. Because when I use CalendarContract class in my project it shows error. So I am not able to find the clue what to do and how to used this class in my project that I have created using Android OS 2.2.

If anyone has any samples to share or a link to samples, please let me know.

Calendar Api Class

public abstract class CalendarAPI 
{
private static CalendarAPI api;

public static CalendarAPI getAPI() 
{
    String apiClass;
    if (Integer.parseInt(Build.VERSION.SDK) > Build.VERSION_CODES.FROYO) {
        apiClass = "com.example.calendar.CycleManagerSDK8 ";
    } else {
        apiClass = "com.example.calendar.CycleManagerSDK14 ";
    }

    try 
    {
        Class<? extends CalendarAPI> realClass = Class.forName(apiClass).asSubclass(CalendarAPI.class);
        api = realClass.newInstance();
    } 
    catch (Exception e) 
    {
        throw new IllegalStateException(e);
    }

    return api;
}

public abstract boolean setAlertOnDevice(Context c) ;
}

class for SDKVersion 8 – 13

public class CycleManagerSDK8 extends CalendarAPI
{
public boolean setAlertOnDevice(Context c)
{                   
    Resources res = c.getResources();

    Uri EVENTS_URI = Uri.parse("content://com.android.calendar/" + "events");

    Uri REMINDERS_URI = Uri.parse("content://com.android.calendar/" + "reminders");

        ContentResolver cr = c.getContentResolver();

    Date dtStartDate = getStartDate();  

    Calendar cal = Calendar.getInstance();

    cal.setTime(dtStartDate);
    cal.add(Calendar.DATE, m_iStart);

    cal.set(Calendar.HOUR_OF_DAY, 8);  
    cal.set(Calendar.MINUTE, DEFAULT_TIME_OF_DATE);     
    cal.set(Calendar.SECOND, DEFAULT_TIME_OF_DATE); 
    cal.set(Calendar.MILLISECOND, DEFAULT_TIME_OF_DATE);

    String str = m_reminderText + res.getString(R.string.alert_start);                                          
    m_strDescription = res.getString(R.string.alert_start_msg);

    ContentValues values = new ContentValues();
    values.put("calendar_id", 1);
    values.put("title", str);
    values.put("description", m_strDescription);                    
    values.put("dtstart", cal.getTimeInMillis()); 
    values.put("dtend", cal.getTimeInMillis()); 
    values.put("hasAlarm", 1);
    Uri event = cr.insert(EVENTS_URI, values);

    m_calendarEvents[m_calendarEventCount] = event;
    m_calendarEventCount = m_calendarEventCount + 1;

    values = new ContentValues();
    values.put("event_id", Long.parseLong(event.getLastPathSegment()));
    values.put("method", 1);
    values.put("minutes", 10);
    cr.insert(REMINDERS_URI, values);
}

}

class for SDKVersion 14

 public class CycleManagerSDK14 extends CalendarAPI
 {
      public void setAlertOnDevice(Context c)
     {
        long startMillis = 0; 
        long endMillis = 0;     
        Calendar beginTime = Calendar.getInstance();
        beginTime.set(2012, 2, 2, 7, 0);
        startMillis = beginTime.getTimeInMillis();
        Calendar endTime = Calendar.getInstance();
        endTime.set(2012, 2, 2, 7, 0);
        endMillis = endTime.getTimeInMillis();

        ContentResolver cr = getContentResolver();
        ContentValues values = new ContentValues();

        values.put(CalendarContract.Events.DTSTART, startMillis);
        values.put(CalendarContract.Events.DTEND, endMillis);
        values.put(CalendarContract.Events.TITLE, "Walk The Dog");
        values.put(CalendarContract.Events.DESCRIPTION, "My dog is bored, so we're going on a really long walk!");
        values.put(CalendarContract.Events.CALENDAR_ID, 1);
        values.put(CalendarContract.Events.EVENT_TIMEZONE, "eventTimezone");
            cr.insert(CalendarContract.Events.CONTENT_URI, values);
    }

}

Thank you.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T14:10:55+00:00Added an answer on May 31, 2026 at 2:10 pm

    As I understand, you have 2 problems…

    1. You need to access Calender in 2.2 (API 8 and above)
    2. From API 14, you need to use CalendarContract to access the Calendar

    My suggestion would be Create a abstract class and define the individual implementation.

    For example

    String apiClass;
    if (Integer.parseInt(Build.VERSION.SDK) > Build.VERSION_CODES.DONUT) {
        apiClass = "com.example.calendar.version8plus";
    } else {
        apiClass = "com.example.calendar.version14plus";
    }
    
    try {
        Class<? extends CalendarAPI> realClass = Class.forName(apiClass).asSubclass(CalendarAPI.class);
        api = realClass.newInstance();
    } catch (Exception e) {
        throw new IllegalStateException(e);
    }
    

    With this, you create two different implementation as per the apis…

    While compiling depending on your API level exclude the other file from compiling, for this you need to change the API level in Manifest.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I use the undocumented API's for calendar integration for Android OS 2.2. Now that
Use case: I've just entered insert mode, and typed some text. Now I want
Instead of Google Maps API's default info window, I'm going to use other jQuery
It used to be that in Carbon you could use SetMenuItemKeyGlyph. What's the alternative
I found some private (undocumented) APIs but Apple does not allow apps to use
After the launch of android 4, CalendarContract class is introduce to write event in
I'm dealing with an undocumented API that I'm trying to do a bit of
I'm attempting to use the undocumented system procedure sp_MSforeachtable . But I need to
I read some info regarding getting .h files for undocumented API. Most of sources
Is there a hidden/undocumented API call within Windows that will convert a message ID

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.