2010-09-17 85 views
1

我想在我的android应用程序中以网格视图格式使用日历,并且它会显示特定日期的事件和图像。日历视图android

是否有任何可以使用的日历罐?

+0

关于Android的日历中的另一个问题:http://stackoverflow.com/a/8242625/119895 – Macarse 2012-02-20 14:30:07

回答

2

下面是关于如何使用访问谷歌日历从Android的

只需输入您的用户ID(以@ gmail.com),密码,选择任一日期,然后按查询按钮样本。

这里的应用程序的肉:

import com.google.android.gdata.client.AndroidXmlParserFactory; 
import com.google.android.gdata.client.JakartaGDataClient; 
import com.google.wireless.gdata.calendar.client.CalendarClient; 
import com.google.wireless.gdata.calendar.data.EventEntry; 
import com.google.wireless.gdata.calendar.data.When; 
import com.google.wireless.gdata.calendar.parser.xml.XmlCalendarGDataParserFactory; 
import com.google.wireless.gdata.client.QueryParams; 
import com.google.wireless.gdata.data.Feed; 
import com.google.wireless.gdata.parser.GDataParser; 

    /** 
    * When the user clicks on the lookup button we use the ATOM/GData API to fetch the 
    * details of events for a specific date 
    * @param view 
    */ 
    public void onClick(View view) { 
     XmlCalendarGDataParserFactory factory = new XmlCalendarGDataParserFactory(new AndroidXmlParserFactory()); 
     JakartaGDataClient dataClient = new JakartaGDataClient(); 

     // Generate the URL for a private ATOM feed in google calendar 
     String url = "http://www.google.com/calendar/feeds/" + 
       dataClient.encodeUri(mUserId.getText().toString()) + "/private/full"; 
     QueryParams params = dataClient.createQueryParams(); 
     String pad1 = (mMonth + 1) < 10 ? "0" : ""; 
     String pad2 = mDay < 10 ? "0" : ""; 
     params.setParamValue("start-min", mYear + "-" + pad1 + (mMonth + 1) + "-" + pad2 + mDay + "T00:00:00"); 
     params.setParamValue("start-max", mYear + "-" + pad1 + (mMonth + 1) + "-" + pad2 + mDay + "T23:59:59"); 
     url = params.generateQueryUrl(url); 
     Log.i("GoogleContacts", "URL :" + url); 

     CalendarClient client = new CalendarClient(dataClient, factory, url); 
     try { 
      Log.i("GoogleContacts", "BaseFeedUrl:" + client.getBaseFeedUrl()); 

      String user = mUserId.getText().toString(); 
      String password = mPassword.getText().toString(); 
      Log.i("GoogleContacts", "userid:" + user); 
      Log.i("GoogleContacts", "password:" + password); 

      // Get the google token 
      String authToken = client.getAuthToken(user, password); 
      Log.i("GoogleContacts", "Token:" + authToken); 

      // Use the token and access the actual feed. 
      java.io.InputStream is = dataClient.getFeedAsStream(url, authToken); 
      GDataParser parser = factory.createParser(is); 
      Feed feed = parser.init(); 

      int totalResults = feed.getTotalResults(); 
      Log.i("GoogleContacts", "Results:" + totalResults); 

      // wade thru the entries and pick interesting information 
      EventEntry entry = null; 
      String[] items = new String[totalResults]; 
      for (int i = 0; i < totalResults; i++) { 
       entry = (EventEntry) parser.readNextEntry(entry); 
       Log.i("GoogleContacts", "Entry ID:" + entry.getId()); 
       Log.i("GoogleContacts", "Entry Title:" + entry.getTitle()); 
       Log.i("GoogleContacts", "Update Date:" + entry.getUpdateDate()); 
       When when = entry.getFirstWhen(); 
       Date time1 = zulu.parse(when.getStartTime()); 
       Date time2 = zulu.parse(when.getEndTime()); 
       Log.i("GoogleContacts", "Date/Time: FROM " + zulu2.format(time1) + " TO " + zulu2.format(time2)); 
       items[i] = zulu2.format(time1) + " - " + zulu2.format(time2) + " : " + entry.getTitle(); 
      } 

      // Display the information in the list view 
      ListView listView = (ListView) findViewById(R.id.data); 
      listView.setAdapter(new ArrayAdapter(this, 
        android.R.layout.simple_list_item_1, 
        items)); 
     } catch (Exception e) { 
      Log.e("GoogleContacts", e.toString(), e); 
     } 
    } 
+0

参考这个网址,我希望这可以工作的HTTP:/ /www.developer.com/ws/article.php/3850276/Working-with-the-Android-Calendar.htm – 2010-09-17 15:58:52

+0

谢谢Sankar ....但我不能使用谷歌日历...因为它不会脱机工作... – Andy 2010-09-18 05:02:37

+0

@Shalini Singh:那么你是如何实现这个 – 2010-09-18 12:38:47