我使用Google Calendar API来获取活动。获取事件后,Event对象不包含事件ID的长值。我想通过Google日历应用将事件ID用于查看活动详情。
谁能告诉我怎么做?
compile('com.google.apis:google-api-services-calendar:v3-rev125-1.20.0') {
exclude group: 'org.apache.httpcomponents'
}
我正在使用这种方法,但我认为这不是一个好习惯。
private static final String[] INSTANCE_PROJECTION = new String[]{
CalendarContract.Instances.EVENT_ID, // 0
CalendarContract.Instances.BEGIN, // 1
CalendarContract.Instances.END, // 1
CalendarContract.Instances.TITLE // 2
};
private static final int PROJECTION_ID_INDEX = 0;
private static final int PROJECTION_BEGIN_INDEX = 1;
private static final int PROJECTION_END_INDEX = 2;
private static final int PROJECTION_TITLE_INDEX = 3;
public long getEventId(String title) {
Cursor cursor = contentResolver.query(builder.build(),
INSTANCE_PROJECTION,
null,
null,
null);
long eventIDL = 0;
long beginVal = 0;
long endVal = 0;
String _title = null;
int size = cursor.getCount();
while (cursor.moveToNext()) {
// Get the field values
eventIDL = cursor.getLong(PROJECTION_ID_INDEX);
beginVal = cursor.getLong(PROJECTION_BEGIN_INDEX);
endVal = cursor.getLong(PROJECTION_END_INDEX);
_title = cursor.getString(PROJECTION_TITLE_INDEX);
if (beginVal == eventDate.getDateStart() && endVal == eventDate.getDateEnd()) {
if (title != null && _title != null) {
if (title.equals(_title)) {
break;
}
}
if (title == null && _title == null) {
break;
}
if (title == null && _title != null && _title.isEmpty()) {
break;
}
if (title != null && title.isEmpty() && _title != null && _title.isEmpty()) {
break;
}
}
}
return eventIDL;
}