Hi Andreas, Did you get the answer, put all user permissions in manifest and try.
Thanks Nithin On Apr 8, 4:21 am, andreas <andreas.str...@googlemail.com> wrote: > Hi, > > I'm really just a beginner and fiddling a little bit around with java > and my G1. I'd like to create acalendarevent from the phone and > learned, that there is no AndroidAPIfor thecalendar. > > I thought it should be possible to access the googlecalendarvia web. > I googled a bit and found some code to try. If I start it as a java > programm on my home pc, it works well and adds an event to mycalendar: > > 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("http://www.google.com/calendar/feeds/MYEMAIL/ > private/full"); > 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, "m...@home.com'); > 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); > } > > } > > Great. Now I tried to put that into a Android application: > > 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("http://www.google.com/calendar/feeds/MYEMAIL/ > private/full"); > } 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, "m...@home.com'); > 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 nocalendarentry anywhere. > > Any pro out there who can give me a hint, what I am doing wrong? > > Greetings, > Andreas --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers-unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en -~----------~----~----~----~------~----~------~--~---