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 6052881
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T07:58:40+00:00 2026-05-23T07:58:40+00:00

I try to create an event and add an email to it. i cant

  • 0

I try to create an event and add an email to it.

i cant get it work, the time i get is 1970 and no email apears.

any ideas?

Thanks.

This is the code i use:

    Uri calendars = null;
   if (Integer.parseInt(Build.VERSION.SDK) == 8 )
   {
         calendars = Uri.parse("content://com.android.calendar/calendars");
   }
   else
   {
          calendars = Uri.parse("content://calendar/calendars");
   }

   Cursor cursor = context.getContentResolver().query(calendars,                                                                  new String[] { "_id", "displayName" },                                                    "selected=1",                                                   null,                                                   null);

   if (cursor != null && cursor.moveToFirst()) 
   {
       String[] calNames = new String[cursor.getCount()];
   final int[] calIds = new int[cursor.getCount()];
   for (int i = 0; i < calNames.length; i++) 
   {
    // retrieve the calendar names and ids               
    calIds[i] = cursor.getInt(0);
    calNames[i] = cursor.getString(1);
    cursor.moveToNext();
   } 
cursor.close();
    String name = "Name1";
    String eMail = "name1@nnn.com";
    ContentValues event = new ContentValues();

    int cal_id = calIds[which];
    event.put("calendar_id", cal_id);
    event.put("title", "test title");
    event.put("eventLocation", "test location");            
    event.put("eventStatus", 1);
    event.put("visibility", 0);
    event.put("transparency", 0);
    event.put("hasAlarm", 1);
    event.put("hasAttendeeData", "1");

    Calendar c = Calendar.getInstance();
    c.roll(Calendar.DAY_OF_MONTH, true);

    Date date = c.getTime();
    Date begine = new Date(date.getYear(), 
            date.getMonth(), 
            date.getDate(), 
            14, 0);         long dtstart = begine.getTime();
    event.put("dtstart", dtstart);

    Date end = new Date(date.getYear(), 
                date.getMonth(), 
                date.getDate(), 
                15, 0);
    long dtend = end.getTime();

    event.put("dtend", dtend);
Uri eventsUri = null;
    if (Integer.parseInt(Build.VERSION.SDK) == 8 )
    {
       eventsUri = Uri.parse("content://com.android.calendar/events");
    }
    else
{
      eventsUri = Uri.parse("content://calendar/events");
    }
    Uri url = context.getContentResolver().insert(eventsUri, event);
    long id = -1;

    if (url != null) 
    {
         id = Long.parseLong(url.getLastPathSegment());
        ContentValues values = new ContentValues();
        values.put("event_id", id);
        values.put("method", 1); //METHOD_ALERT
        values.put("minutes", 15); // 15 minutes
        Uri reminder = Uri.parse("content://com.android.calendar/reminders");
            context.getContentResolver().insert(reminder, values);
        if(name.length() > 0 || eMail.length() > 0)
        {
            ContentValues attendees = new ContentValues();
            attendees.put("attendeeEmail", eMail);
            attendees.put("attendeeName", name);
            attendees.put("attendeeRelationship", 2);//RELATIONSHIP_ATTENDEE
            attendees.put("attendeeStatus", 3); //ATTENDEE_STATUS_INVITED       
            attendees.put("attendeeType", 1); //TYPE_REQUIRED
            attendees.put("event_id", id);

            Uri attendeesUri = null;
            if (Integer.parseInt(Build.VERSION.SDK) == 8 )
            {
                     attendeesUri = Uri.parse("content://com.android.calendar/attendees");
            }
                else
                {
                    attendeesUri = Uri.parse("content://calendar/attendees");
                }
            context.getContentResolver().insert(attendeesUri, attendees);

            Intent i = new Intent(Intent.ACTION_EDIT); 

            i.setType("vnd.android.cursor.item/event");
            i.setData(url);

            context.startActivity(i);
        }
        else
        {
            Toast.makeText(context, "Could not create an event!", Toast.LENGTH_LONG);               
        }
  • 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-23T07:58:40+00:00Added an answer on May 23, 2026 at 7:58 am

    The time for dtStart and dtEnd should be in milliseconds after the Epoch (Jan. 1, 1970) use this link epoch time converter to get the current time. Multiply the time it gives you on that site by 1000 because it returns it in seconds instead of milliseconds.

    Also, dtEnd and dtStart is of the “long” type.

    Long dtStart
    Long dtEnd
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is in C# So I'm trying to create an event for ProgressChanged for
I have Buttons attached to elements on the modules entrypoint html page using RootPanel.get(foo).add(button)
I try in GWT to create a Tree with multiple selection for the nodes
When I try to use the KeyRelease event on the Tkinter Text widget, it
I try using Devexpress Layout-Control (For costume usage). So I want add all item's
So basically I am trying to create instances of the class below every time
In this page there's a way to dynamic add html (textbox,input button and radio
I come across this problem when i am writing an event handler in SharePoint.
many people seem to have problem in making this work, so i am not
I have specific troubles when I try create node. From context menu everything gona

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.