0
我正在嘗試開發一個android應用程序,其中我需要獲取所有日曆條目(提醒),保存在手機日曆中,我如何獲取它們?我可以在android模擬器上做嗎?如何在我的應用程序的android中獲取保存的提醒
我正在嘗試開發一個android應用程序,其中我需要獲取所有日曆條目(提醒),保存在手機日曆中,我如何獲取它們?我可以在android模擬器上做嗎?如何在我的應用程序的android中獲取保存的提醒
我得到這個code.See,它可以幫助你
Cursor cursor = cr.query(Uri.parse("content://calendar/events"), new String[]{ "calendar_id", "title", "description", "dtstart", "dtend", "eventLocation" }, null, null, null);
//Cursor cursor = cr.query(Uri.parse("content://calendar/calendars"), new String[]{ "_id", "name" }, null, null, null);
String add = null;
cursor.moveToFirst();
String[] CalNames = new String[cursor.getCount()];
int[] CalIds = new int[cursor.getCount()];
for (int i = 0; i < CalNames.length; i++) {
CalIds[i] = cursor.getInt(0);
CalNames[i] = "Event"+cursor.getInt(0)+": \nTitle: "+ cursor.getString(1)+"\nDescription: "+cursor.getString(2)+"\nStart Date: "+new Date(cursor.getLong(3))+"\nEnd Date : "+new Date(cursor.getLong(4))+"\nLocation : "+cursor.getString(5);
if(add == null)
add = CalNames[i];
else{
add += CalNames[i];
}
((TextView)findViewById(R.id.calendars)).setText(add);
cursor.moveToNext();
}
cursor.close();
的GData既過時,並與衆多Android版本不兼容。
閱讀this將有所幫助。
這是無證和不受支持的。谷歌一再告訴你不要使用無證內容提供商。此代碼不適用於所有Android版本。此內容提供商甚至可能不存在於任何給定設備上。 Google可能會關閉對這個內容提供商的訪問權限,就像他們與其他人一樣。請使用Google日曆GData API來操作用戶的Google日曆。 – CommonsWare