• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Apps Calendar Entry

You could use the google calendar api to insert it on the users calendar. You should be able to new up a CalendarService (the service var in the code snipplet) with the users user name and password then add an event with a method call like the below:

Code:
public CalendarEventEntry addEvent(String eventTitle, String eventContent, Calendar startCalTime, int durationMinutes, WebContent wc) throws ServiceException, IOException
    {
        CalendarEventEntry myEntry = new CalendarEventEntry();

        myEntry.setTitle(new PlainTextConstruct(eventTitle));
        myEntry.setContent(new PlainTextConstruct(eventContent));
        myEntry.setQuickAdd(false);
        myEntry.setWebContent(wc);

        DateTime startTime = new DateTime(startCalTime.getTime(), TimeZone.getDefault());

        startCalTime.add(Calendar.MINUTE, durationMinutes);
        DateTime endTime = new DateTime(startCalTime.getTime(), TimeZone.getDefault());

        When eventTimes = new When();
        eventTimes.setStartTime(startTime);
        eventTimes.setEndTime(endTime);
        myEntry.addTime(eventTimes);

        return service.insert(eventFeedUrl, myEntry);
    }
most of this code is taken from the samples in the google calendar api, and it will have much more information and useful source code.
 
Upvote 0
Hi,

I'm really just a beginner and fiddling a little bit around with java
and my G1. I'd like to create a calendar event from the phone and
learned, that there is no Android API for the calendar - and I found this thread and some similiar code snippets.

So I tried that as a java program on my pc:

Code:
 com.google.gdata.client.calendar.CalendarService;
import com.google.gdata.data.DateTime;
import com.google.gdata.data.Person;
import com.google.gdata.data.PlainTextConstruct;
import com.google.gdata.data.extensions.EventEntry;
import com.google.gdata.data.extensions.When;
import com.google.gdata.util.ServiceException;
import java.io.IOException;
import java.net.URL;

public class TestMyCal {

       /**
        * @param args
        */
       public static void main(String[] args) throws IOException,
ServiceException {
       // Set up the URL and the object that will handle the
connection:
               URL postUrl = new URL("[URL="http://www.google.com/calendar/feeds/MYEMAIL/private/full"]http://www.google.com/calendar/
feeds/MYEMAIL/
private/full[/URL]");
       CalendarService myService = new CalendarService("exampleCo-
exampleApp-1");
               myService.setUserCredentials("MYNAME", "MYPASSWORD");

       EventEntry myEntry = new EventEntry();

       myEntry.setTitle(new PlainTextConstruct("My test event"));
       myEntry.setContent(new PlainTextConstruct("It might work."));

       Person author = new Person("It's me", null, "[EMAIL="me@home.com"]me@home.com[/EMAIL]');
       myEntry.getAuthors().add(author);

       DateTime startTime = DateTime.parseDateTime
("2009-04-08T15:00:00-08:00");
       DateTime endTime = DateTime.parseDateTime
("2009-04-08T17:00:00-08:00");
       When eventTimes = new When();
       eventTimes.setStartTime(startTime);
       eventTimes.setEndTime(endTime);
       myEntry.addTime(eventTimes);

       // Send the request and receive the response:
       EventEntry insertedEntry = myService.insert(postUrl, myEntry);
   }

}
It works, great. I find that entry in my calendar. Now I tried to put that into a Android application:

Code:
 package com.android.hello;

import android.app.Activity;
import android.os.Bundle;
import com.google.gdata.client.calendar.CalendarService;
import com.google.gdata.data.DateTime;
import com.google.gdata.data.Person;
import com.google.gdata.data.PlainTextConstruct;
import com.google.gdata.data.extensions.EventEntry;
import com.google.gdata.data.extensions.When;
import com.google.gdata.util.AuthenticationException;
import com.google.gdata.util.ServiceException;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;

public class HelloAndroid extends Activity {
   /** Called when the activity is first created. */
   @Override
   public void onCreate(Bundle savedInstanceState) {
       super.onCreate(savedInstanceState);
       // Set up the URL and the object that will handle the
connection:
       URL postUrl = null;
               try {
                       postUrl = new URL("[URL="http://www.google.com/calendar/feeds/MYEMAIL/private/full"]http://www.google.com/
calendar/feeds/MYEMAIL/
private/full[/URL]");
               } catch (MalformedURLException e) {
                       // TODO Auto-generated catch block
                       e.printStackTrace();
               }

       CalendarService myService = new CalendarService("exampleCo-
exampleApp-1");
               try {
                       myService.setUserCredentials("MYNAME",
"MYPASSWORD");
               } catch (AuthenticationException e) {
                       // TODO Auto-generated catch block
                       e.printStackTrace();
               }

       EventEntry myEntry = new EventEntry();

       myEntry.setTitle(new PlainTextConstruct("My test event"));
       myEntry.setContent(new PlainTextConstruct("It might work."));

       Person author = new Person("It's me", null, "[EMAIL="me@home.com"]me@home.com[/EMAIL]');
       myEntry.getAuthors().add(author);

       DateTime startTime = DateTime.parseDateTime
("2009-04-08T15:00:00-08:00");
       DateTime endTime = DateTime.parseDateTime
("2009-04-08T17:00:00-08:00");
       When eventTimes = new When();
       eventTimes.setStartTime(startTime);
       eventTimes.setEndTime(endTime);
       myEntry.addTime(eventTimes);

               try {
                       EventEntry insertedEntry = myService.insert
(postUrl, myEntry);
               } catch (IOException e) {
                       // TODO Auto-generated catch block
                       e.printStackTrace();
               } catch (ServiceException e) {
                       // TODO Auto-generated catch block
                       e.printStackTrace();
               }

       setContentView(R.layout.main);
   }
}
The program just runs fine, no errors (not using the emulator, not
using the G1) - but there is no calendar entry anywhere.

Any pro out there who can give me a hint, what I am doing wrong?

Greetings,
bingi
 
Upvote 0
HII

CAN ANYONE PLEASE HELP ME OUT IN ONE ISSSUE I AM STUCKED IN AND I FEEL THIS IS THE PROPER PLACE TO HAVE THE SOLUTION I REALY NEED YOUR HELP AND SUPPORT.............

THE ISSUE IS THAT WITH OFFLINE CALENDAR IN ANDROID PHONE - THE ISSUE THAT REPRODUCED IS WHEN I AM ENTERING THE CLENDAR API THEN CLICKING ON MENU -> MORE -> CALENDARS -> MENU -> CREATE CALENDARS -> THEN COMING BACK TO HOME SCREEN ADN REBOOTING MY PHONE THEN THE OFFLINE CALENDAR IS GETTING DISSAPEARED WITHOUT GETTING STORED......

I CHECKED THE CODE FROM IT INSIDE THE CreateOfflineCalendar.java package THE CODE SEEMS AS IF IT IS INSERTING THE DATS BUT NOT COMMITING IT........


CAN ANYONE HELPME OUT HOW TO SAVE THAT OR TO COMMIT IT IN THE DATABASE........................
YOU CAN MAIL ME TO ..............SAMYAK.ROUT@GMAIL.COM................... WAITING FOR YOUR REPLIES FRIENDS...................
 
Upvote 0

BEST TECH IN 2023

We've been tracking upcoming products and ranking the best tech since 2007. Thanks for trusting our opinion: we get rewarded through affiliate links that earn us a commission and we invite you to learn more about us.

Smartphones