gpt4 book ai didi

android - 从 CalendarContract 获取与会者详细信息

转载 作者:行者123 更新时间:2023-11-29 21:24:56 25 4
gpt4 key购买 nike

我正在尝试创建一个应用程序,它将从设备上的日历应用程序中获取 EventsAttendees 的详细信息。

我面临的问题是:

1).在许多 Activity 中,标题和参加者不匹配。

2).在许多 Activity 中,我的参加人数为 0(主要是为了即将举行的 Activity )。

这是我的代码:(请让我知道错误)。

public class ReadCalendar {
static Cursor cursor;

public static void readCalendar(Context context) {

ContentResolver contentResolver = context.getContentResolver();

// Fetch a list of all calendars synced with the device, their display names and whether the

cursor = contentResolver.query(Uri.parse("content://com.android.calendar/calendars"),
(new String[] { Calendars._ID, Calendars.NAME}), null, null, null);

HashSet<String> calendarIds = new HashSet<String>();

try
{
System.out.println("Count="+cursor.getCount());
if(cursor.getCount() > 0)
{
System.out.println("the control is just inside of the cursor.count loop");
while (cursor.moveToNext()) {

String _id = cursor.getString(0);
String displayName = cursor.getString(1);
//Boolean selected = !cursor.getString(2).equals("0");

System.out.println("Id: " + _id + " Display Name: " + displayName);
calendarIds.add(_id);
}
}
}
catch(AssertionError ex)
{
ex.printStackTrace();
}
catch(Exception e)
{
e.printStackTrace();
}


// For each calendar, display all the events from the previous week to the end of next week.
for (String id : calendarIds) {
Uri.Builder builder = Uri.parse("content://com.android.calendar/instances/when").buildUpon();
//Uri.Builder builder = Uri.parse("content://com.android.calendar/calendars").buildUpon();
long now = new Date().getTime();

ContentUris.appendId(builder, now - DateUtils.DAY_IN_MILLIS * 10000);
ContentUris.appendId(builder, now + DateUtils.DAY_IN_MILLIS * 10000);

Log.e("123", "Calender ID---->>>>>>"+id);
Cursor eventCursor = contentResolver.query(builder.build(),
new String[] { Events.TITLE, "begin", "end", "allDay", Events._ID, Events.CALENDAR_ID}, Events.CALENDAR_ID+"=" + id,
null, "_id ASC");

Log.e("123","eventCursor count====="+eventCursor.getCount());
if(eventCursor.getCount()>0)
{

if(eventCursor.moveToFirst())
{
do
{
Object mbeg_date,beg_date,beg_time,end_date,end_time;

final String title = eventCursor.getString(0);
final Date begin = new Date(eventCursor.getLong(1));
final Date end = new Date(eventCursor.getLong(2));
final Boolean allDay = !eventCursor.getString(3).equals("0");
final String eventId = eventCursor.getString(4);
final String calendarID = eventCursor.getString(5);

Log.e("123", "Event Id----->>>>>"+eventId+"---------calendarId----->>>"+calendarID);

/* System.out.println("Title: " + title + " Begin: " + begin + " End: " + end +
" All Day: " + allDay);
*/
Log.e("123","Title:"+title);
Log.e("123","Begin:"+begin);
Log.e("123","End:"+end);
Log.e("123","All Day:"+allDay);

// Attendees Code
Cursor eventAttendeesCoursor = contentResolver.query(CalendarContract.Attendees.CONTENT_URI, new String []{ Attendees.ATTENDEE_NAME, Attendees.EVENT_ID}, Attendees.EVENT_ID +" = " + eventId, null, null);
Log.e("123", "Count of no of attendees-----"+eventAttendeesCoursor.getCount());
if(eventAttendeesCoursor.getCount()>0)
{

if(eventAttendeesCoursor.moveToFirst())
{
do {
// Log.e("123", "Attendees Name---->>>"+ eventAttendeesCoursor.getString(0));
Log.e("123", "Attendees Event ID---->>>"+ eventAttendeesCoursor.getString(1));
} while(eventAttendeesCoursor.moveToNext());
}
}

}
while(eventCursor.moveToNext());
}
}
break;
}
}
}

最佳答案

我没有详细查看您的代码,但我遇到了同样的问题 - 这是因为实例 ID 和事件 ID 之间的混淆。我确实看到您的 uri(构建器)是基于实例的,但是您需要的字段是 event.id :它们是不同的。

重要的是 attendees 表是基于 EVENT id - 而不是实例 id - 所以它可能会解释你的问题。始终如一地按顺序排列(即,根据您的 URI 从 INSTANCE 表中提取 EVENT id,并将其传递给 ATTENDEES 表。看看是否有帮助。

关于android - 从 CalendarContract 获取与会者详细信息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20321710/

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