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

  • SEARCH
  • Home
  • 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 8754821
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T13:42:56+00:00 2026-06-13T13:42:56+00:00

I’ve been coding a sort of alarm app, just for myself for the time

  • 0

I’ve been coding a sort of alarm app, just for myself for the time being, but I might put it up for free if anybody wants it when it’s done. In any case, I’ve been stymied. All I want from the calendar is the next event in the user’s calendar so I can display the title, time, time until, and location.

Here’s what I’ve got so far:

    //get cursor to first row of table of events
        mCursor = getContentResolver().query(
        CalendarContract.Events.CONTENT_URI, COLS, null, null, null);
        mCursor.moveToFirst();

        //variables; title, startdate in miliseconds, etc
        String nextAppointmentTitle = "N/A";
        Long start = 0L;            //tf(start) for appointmentTime
        String timeUntilNextAppointment = "N/A";
        String nextAppointmentLocation = "N/A";


        Format df = DateFormat.getDateFormat(this);
        Format tf = DateFormat.getTimeFormat(this);
        try {
        nextAppointmentTitle = mCursor.getString(0);
        start = mCursor.getLong(1);
        } catch (Exception e) {
        //ignore for the time being
        }


        //create a date object for the time of the event
        GregorianCalendar appointmentTime = (GregorianCalendar) GregorianCalendar.getInstance();
        appointmentTime.setTimeInMillis(start);
        //create date object for current time       
        GregorianCalendar now = (GregorianCalendar) GregorianCalendar.getInstance();

        //get the time from current time until start of event
        long millisUntilNextMeeting = (long) appointmentTime.getTimeInMillis() - (long) now.getTimeInMillis();
        GregorianCalendar timeUntilNextMeeting = (GregorianCalendar) GregorianCalendar.getInstance();
        timeUntilNextMeeting.clear();
        timeUntilNextMeeting.setTime(new Date(millisUntilNextMeeting));

        millisUntilNextMeeting= (millisUntilNextMeeting/1000) /60;

        if (timeUntilNextMeeting.get(GregorianCalendar.HOUR_OF_DAY) > 0) {
            int hours = timeUntilNextMeeting.get(GregorianCalendar.HOUR_OF_DAY) + 6;
            timeUntilNextAppointment = "" + hours + " hours";
        } else {
            timeUntilNextAppointment = "" + timeUntilNextMeeting.get(GregorianCalendar.MINUTE) + " minutes";
        } 
// ... do things with values

Rather than showing my next appointment, it’s showing Alberta Family Day, which apparently takes place in February. I did some looking around with my calendars and it appears that it has arbitrarily selected my “Canadian Holidays” calendar that Google so helpfully added to my phone, instead of the one I actually put things in. I can’t seem to figure out how to select the correct calendar without resorting to having the user select it every time.

Does anybody know offhand how I would get the values I want from the calendar I want? I’d really appreciate a hand.

PS I know that this app won’t work on pre 4.0 devices, but I don’t care enough to throw another 4 hours at trying to decipher the horrible google api docs.

  • 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-06-13T13:42:57+00:00Added an answer on June 13, 2026 at 1:42 pm

    First find the calendar you want by using constants in CalendarContract.Calendars. Query on either NAME or CALENDAR_DISPLAY_NAME. From the returned row, get the _ID value. Use this value to query CalendarContract.Events.CALENDAR_ID. That will give you all the events for the calendar identified by CalendarContract.Events.CALENDAR_ID.

    What you were doing is grabbing all the events for all calendars.

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

Sidebar

Related Questions

I have a jquery bug and I've been looking for hours now, I can't
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I have a French site that I want to parse, but am running into
This could be a duplicate question, but I have no idea what search terms
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build
Seemingly simple, but I cannot find anything relevant on the web. What is the

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.