gpt4 book ai didi

android - 日历与android中的自定义添加帐户同步

转载 作者:太空宇宙 更新时间:2023-11-03 13:31:53 25 4
gpt4 key购买 nike

我想在日历中添加事件,我可以添加帐户,但我不知道如何与日历同步。

我应该创建一个新的日历 ID 吗?如何验证事件是否已在日历上创建?

最佳答案

看看这个 Google code project 这将指导您。

在该项目中,有一种方法可以为您提供与 Calender 关联的帐户 ID。

private int ListSelectedCalendars() {
int result = 0;
String[] projection = new String[] { "_id", "name" };
String selection = "selected=1";
String path = "calendars";

Cursor managedCursor = getCalendarManagedCursor(projection, selection,
path);

if (managedCursor != null && managedCursor.moveToFirst()) {

Log.i(DEBUG_TAG, "Listing Selected Calendars Only");

int nameColumn = managedCursor.getColumnIndex("name");
int idColumn = managedCursor.getColumnIndex("_id");

do {
String calName = managedCursor.getString(nameColumn);
String calId = managedCursor.getString(idColumn);
Log.i(DEBUG_TAG, "Found Calendar '" + calName + "' (ID="
+ calId + ")");
// You have to give email id in below line, right now i puted my email id
if (calName != null && calName.contains("vimalrajpara2006@gmail.com")) {
result = Integer.parseInt(calId);
}
} while (managedCursor.moveToNext());
} else {
Log.i(DEBUG_TAG, "No Calendars");
}

return result;

}

您可以根据该 ID 添加事件以及进行搜索。

private Uri MakeNewCalendarEntry(int calId/*Value received from ListSelectedCalendars function*/) {
ContentValues event = new ContentValues();

event.put("calendar_id", calId);
event.put("title", "Today's Event [TEST]");
event.put("description", "2 Hour Presentation");
event.put("eventLocation", "Online");

long startTime = System.currentTimeMillis() + 1000 * 60 * 60;
long endTime = System.currentTimeMillis() + 1000 * 60 * 60 * 2;

event.put("dtstart", startTime);
event.put("dtend", endTime);

event.put("allDay", 0); // 0 for false, 1 for true
event.put("eventStatus", 1);
event.put("visibility", 0);
event.put("transparency", 0);
event.put("hasAlarm", 0); // 0 for false, 1 for true

Uri eventsUri = Uri.parse(getCalendarUriBase()+"events");

Uri insertedUri = getContentResolver().insert(eventsUri, event);
return insertedUri;
}

有关更多功能,请查看上面提到的 Google 代码项目。

关于android - 日历与android中的自定义添加帐户同步,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12033224/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com