从我的应用添加事件到谷歌日历

时间:2011-07-20 06:31:24

标签: android gdata-api

我有代码。日食没有错误。但在模拟器中,我得到“应用程序意外停止”错误。我做了很多研究,但我无法摆脱这种情况。我想让应用程序做的就是将事件添加到我的谷歌日历中。

代码段:

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/xyz@gmail.com/private/full");
           } catch (MalformedURLException e) {
                   // TODO Auto-generated catch block
                   e.printStackTrace();
           }

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

   EventEntry myEntry = new EventEntry();

   myEntry.setTitle(new PlainTextConstruct("test event"));
   myEntry.setContent(new PlainTextConstruct("Working!!"));

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

   DateTime startTime = DateTime.parseDateTime("2011-07-20T15:00:00-08:00");
   DateTime endTime = DateTime.parseDateTime("2011-07-20T17: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);
  }

与代码或清单有关吗?

0 个答案:

没有答案