Calendar Entry


Last Updated:

  1. saranya

    saranya Member This Topic's Starter

    Joined:
    Oct 17, 2008
    Messages:
    9
    Likes Received:
    1
    Actually i need to get calendar entries.But I can't find option like calendar entries in emulator.Is this feature available in android or not?
    If it is,Please help me to get Calendar entries.
    Thanks in advance
    saran
     

    Advertisement
  2. jmatthes

    jmatthes New Member

    Joined:
    Nov 25, 2008
    Messages:
    1
    Likes Received:
    0
    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 (Text):
    1. public CalendarEventEntry addEvent(String eventTitle, String eventContent, Calendar startCalTime, int durationMinutes, WebContent wc) throws ServiceException, IOException
    2.     {
    3.         CalendarEventEntry myEntry = new CalendarEventEntry();
    4.  
    5.         myEntry.setTitle(new PlainTextConstruct(eventTitle));
    6.         myEntry.setContent(new PlainTextConstruct(eventContent));
    7.         myEntry.setQuickAdd(false);
    8.         myEntry.setWebContent(wc);
    9.  
    10.         DateTime startTime = new DateTime(startCalTime.getTime(), TimeZone.getDefault());
    11.  
    12.         startCalTime.add(Calendar.MINUTE, durationMinutes);
    13.         DateTime endTime = new DateTime(startCalTime.getTime(), TimeZone.getDefault());
    14.  
    15.         When eventTimes = new When();
    16.         eventTimes.setStartTime(startTime);
    17.         eventTimes.setEndTime(endTime);
    18.         myEntry.addTime(eventTimes);
    19.  
    20.         return service.insert(eventFeedUrl, myEntry);
    21.     }
    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.
     
  3. bingi

    bingi New Member

    Joined:
    Apr 8, 2009
    Messages:
    2
    Likes Received:
    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 (Text):
    1.  com.google.gdata.client.calendar.CalendarService;
    2. import com.google.gdata.data.DateTime;
    3. import com.google.gdata.data.Person;
    4. import com.google.gdata.data.PlainTextConstruct;
    5. import com.google.gdata.data.extensions.EventEntry;
    6. import com.google.gdata.data.extensions.When;
    7. import com.google.gdata.util.ServiceException;
    8. import java.io.IOException;
    9. import java.net.URL;
    10.  
    11. public class TestMyCal {
    12.  
    13.        /**
    14.         * @param args
    15.         */
    16.        public static void main(String[] args) throws IOException,
    17. ServiceException {
    18.        // Set up the URL and the object that will handle the
    19. connection:
    20.                URL postUrl = new URL("[URL="http://www.google.com/calendar/feeds/MYEMAIL/private/full"]http://www.google.com/calendar/
    21. feeds/MYEMAIL/
    22. private/full[/URL]");
    23.        CalendarService myService = new CalendarService("exampleCo-
    24. exampleApp-1");
    25.                myService.setUserCredentials("MYNAME", "MYPASSWORD");
    26.  
    27.        EventEntry myEntry = new EventEntry();
    28.  
    29.        myEntry.setTitle(new PlainTextConstruct("My test event"));
    30.        myEntry.setContent(new PlainTextConstruct("It might work."));
    31.  
    32.        Person author = new Person("It's me", null, "[EMAIL="me@home.com"]me@home.com[/EMAIL]');
    33.        myEntry.getAuthors().add(author);
    34.  
    35.        DateTime startTime = DateTime.parseDateTime
    36. ("2009-04-08T15:00:00-08:00");
    37.        DateTime endTime = DateTime.parseDateTime
    38. ("2009-04-08T17:00:00-08:00");
    39.        When eventTimes = new When();
    40.        eventTimes.setStartTime(startTime);
    41.        eventTimes.setEndTime(endTime);
    42.        myEntry.addTime(eventTimes);
    43.  
    44.        // Send the request and receive the response:
    45.        EventEntry insertedEntry = myService.insert(postUrl, myEntry);
    46.    }
    47.  
    48. }
    49.  
    50.  
    It works, great. I find that entry in my calendar. Now I tried to put that into a Android application:

    Code (Text):
    1.  package com.android.hello;
    2.  
    3. import android.app.Activity;
    4. import android.os.Bundle;
    5. import com.google.gdata.client.calendar.CalendarService;
    6. import com.google.gdata.data.DateTime;
    7. import com.google.gdata.data.Person;
    8. import com.google.gdata.data.PlainTextConstruct;
    9. import com.google.gdata.data.extensions.EventEntry;
    10. import com.google.gdata.data.extensions.When;
    11. import com.google.gdata.util.AuthenticationException;
    12. import com.google.gdata.util.ServiceException;
    13. import java.io.IOException;
    14. import java.net.MalformedURLException;
    15. import java.net.URL;
    16.  
    17. public class HelloAndroid extends Activity {
    18.    /** Called when the activity is first created. */
    19.    @Override
    20.    public void onCreate(Bundle savedInstanceState) {
    21.        super.onCreate(savedInstanceState);
    22.        // Set up the URL and the object that will handle the
    23. connection:
    24.        URL postUrl = null;
    25.                try {
    26.                        postUrl = new URL("[URL="http://www.google.com/calendar/feeds/MYEMAIL/private/full"]http://www.google.com/
    27. calendar/feeds/MYEMAIL/
    28. private/full[/URL]");
    29.                } catch (MalformedURLException e) {
    30.                        // TODO Auto-generated catch block
    31.                        e.printStackTrace();
    32.                }
    33.  
    34.        CalendarService myService = new CalendarService("exampleCo-
    35. exampleApp-1");
    36.                try {
    37.                        myService.setUserCredentials("MYNAME",
    38. "MYPASSWORD");
    39.                } catch (AuthenticationException e) {
    40.                        // TODO Auto-generated catch block
    41.                        e.printStackTrace();
    42.                }
    43.  
    44.        EventEntry myEntry = new EventEntry();
    45.  
    46.        myEntry.setTitle(new PlainTextConstruct("My test event"));
    47.        myEntry.setContent(new PlainTextConstruct("It might work."));
    48.  
    49.        Person author = new Person("It's me", null, "[EMAIL="me@home.com"]me@home.com[/EMAIL]');
    50.        myEntry.getAuthors().add(author);
    51.  
    52.        DateTime startTime = DateTime.parseDateTime
    53. ("2009-04-08T15:00:00-08:00");
    54.        DateTime endTime = DateTime.parseDateTime
    55. ("2009-04-08T17:00:00-08:00");
    56.        When eventTimes = new When();
    57.        eventTimes.setStartTime(startTime);
    58.        eventTimes.setEndTime(endTime);
    59.        myEntry.addTime(eventTimes);
    60.  
    61.                try {
    62.                        EventEntry insertedEntry = myService.insert
    63. (postUrl, myEntry);
    64.                } catch (IOException e) {
    65.                        // TODO Auto-generated catch block
    66.                        e.printStackTrace();
    67.                } catch (ServiceException e) {
    68.                        // TODO Auto-generated catch block
    69.                        e.printStackTrace();
    70.                }
    71.  
    72.        setContentView(R.layout.main);
    73.    }
    74. }
    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
     
  4. bingi

    bingi New Member

    Joined:
    Apr 8, 2009
    Messages:
    2
    Likes Received:
    0
    Well, I learned that the Google Api won't work with Android. I tried several workarounds found on the web, but with no success.

    Since there is no native Android calendar API and the "normal" Google API doesn't work I see no way for me to add a calendar entry.Hmmm...

    Anybody any hint?
     
  5. Graham

    Graham Well-Known Member

    Joined:
    Mar 23, 2009
    Messages:
    89
    Likes Received:
    0
    Is the Calendar app closed source?
    It doesn't appear to be installed on the emulator - can that mean there will never be an API for it?
     
  6. bhuvanaroopa

    bhuvanaroopa New Member

    Joined:
    Jul 14, 2010
    Messages:
    2
    Likes Received:
    0
    i want code for calendar application so pls provide me full code for that its urgent
     
  7. jonbonazza

    jonbonazza Well-Known Member

    Joined:
    Jul 13, 2010
    Messages:
    1,934
    Likes Received:
    458
    Are you serious?
     
  8. Samyak

    Samyak New Member

    Joined:
    Sep 18, 2011
    Messages:
    3
    Likes Received:
    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...................
     

Share This Page

Loading...