これは、カレンダーのいくつかのイベントに関する完全なコードです。これがあなたを助けますように。
import java.text.SimpleDateFormat;
import java.util.Calendar;
import android.app.Activity;
import android.content.ContentResolver;
import android.content.ContentValues;
import android.database.Cursor;
import android.graphics.Color;
import android.net.Uri;
import android.os.Bundle;
import android.provider.CalendarContract.Calendars;
import android.provider.CalendarContract.Events;
import android.util.Log;
public class MainActivity extends Activity {
long calID = 0;
long eventID = 0;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Cursor cur = null;
ContentResolver cr = getContentResolver();
Uri uri = Calendars.CONTENT_URI;
final String[] projection = { Calendars._ID, Calendars.ACCOUNT_NAME,
Calendars.OWNER_ACCOUNT, Calendars.CALENDAR_DISPLAY_NAME };
// Submit the query and get a Cursor object back.
cur = cr.query(uri, projection, null, null, null);
while (cur.moveToNext()) {
String accNme = null;
String accType = null;
String disName = null;
// Get the field values
calID = cur.getLong(0);
accNme = cur.getString(1);
accType = cur.getString(2);
disName = cur.getString(3);
Log.v("log_tag", "calId : " + calID);
Log.v("log_tag", "accNme : " + accNme);
Log.v("log_tag", "accType : " + accType);
Log.v("log_tag", "disName : " + disName);
}
/*long startMillis = 0;
Calendar beginTime = Calendar.getInstance();
beginTime.set(2012, 11, 8, 7, 30);
startMillis = beginTime.getTimeInMillis();
cr = getContentResolver();
ContentValues values = new ContentValues();
values.put(Events.DTSTART, startMillis);
values.put(Events.DURATION, "P60S");
values.put(Events.TITLE, "MyTestNew");
values.put(Events.EVENT_COLOR, Color.MAGENTA);
values.put(Events.DESCRIPTION, "Group workout");
values.put(Events.CALENDAR_ID, calID);
values.put(Events.EVENT_TIMEZONE, "India");
values.put(Events.RRULE, "FREQ=DAILY;INTERVAL=3");
cr.insert(Events.CONTENT_URI, values);
*/
String[] proj = new String[] { Events._ID, Events.DTSTART,
Events.DTEND, Events.RRULE, Events.TITLE };
cur = cr.query(Events.CONTENT_URI, proj, null, null, null);
while (cur.moveToNext()) {
String title = null;
long beginVal = 0;
eventID = cur.getLong(0);
beginVal = cur.getLong(1);
title = cur.getString(4);
Log.v("log_tag", "Event: " + title);
Log.v("log_tag", "eventID: " + eventID);
Calendar calendar = Calendar.getInstance();
calendar.setTimeInMillis(beginVal);
SimpleDateFormat formatter = new SimpleDateFormat("MM/dd/yyyy");
Log.v("log_tag", "DateS: " + formatter.format(calendar.getTime()));
Log.v("log_tag", "DateE: " + cur.getLong(2));
Log.v("log_tag", "RRULE: " + cur.getString(3));
}
/*cr = getContentResolver();
values = new ContentValues();
values = new ContentValues();
uri = ContentUris.withAppendedId(Events.CONTENT_URI, eventID);
values = new ContentValues();
values.put(Events.RRULE, "FREQ=DAILY;INTERVAL=2");
values.put(Events.DURATION, "P1S");
int rows = cr.update(uri, values, null, null);
Log.v("log_tag", "Rows updated: " + rows);*/
cur = cr.query(Events.CONTENT_URI, proj, null, null, null);
while (cur.moveToNext()) {
String title = null;
long eventID = 0;
long beginVal = 0;
eventID = cur.getLong(0);
beginVal = cur.getLong(1);
title = cur.getString(4);
Log.v("log_tag", "Event: " + title);
Log.v("log_tag", "eventID: " + eventID);
Calendar calendar = Calendar.getInstance();
calendar.setTimeInMillis(beginVal);
SimpleDateFormat formatter = new SimpleDateFormat("MM/dd/yyyy");
Log.v("log_tag", "DateS: " + formatter.format(calendar.getTime()));
Log.v("log_tag", "DateE: " + cur.getLong(2));
Log.v("log_tag", "RRULE: " + cur.getString(3));
}
}
}
ここから参考にした