здесь я могу вставить события в календарь.
final ContentResolver cr = getContentResolver();
Cursor cursor ;
//Retrieving calendar sync data
if (Integer.parseInt(Build.VERSION.SDK) == 8 )
cursor = cr.query(Uri.parse("content://com.android.calendar/calendars"), new String[]{ "_id", "displayname" }, null, null, null);
else
cursor = cr.query(Uri.parse("content://calendar/calendars"), new String[]{ "_id", "displayname" }, null, null, null);
if(cursor.moveToFirst())
{
final String[] calNames = new String[cursor.getCount()];
final int[] calIds = new int[cursor.getCount()];
for (int i = 0; i < calNames.length; i++)
{
calIds[i] = cursor.getInt(0);
calNames[i] = cursor.getString(1);
System.out.println("Title: " +calIds[i] + " name " + calNames[i]);
cursor.moveToNext();
}
System.out.println("currenttimeinmillis"+System.currentTimeMillis());
AlertDialog.Builder builder = new AlertDialog.Builder(calendarsync.this);
builder.setSingleChoiceItems(calNames, -1, new DialogInterface.OnClickListener()
{
@Override
public void onClick(DialogInterface dialog, int which)
{
**
// Вставка / синхронизация событий в календаре
**
ContentValues cv = new ContentValues();
cv.put("calendar_id", calIds[which]);
cv.put("title", "Naven");
// set the description of the event
cv.put("description", "Birthday");
// set the event's physical location
// cv.put("eventLocation", );
Calendar d = Calendar.getInstance();
d.set(2012, 0, 10, 3, 0, 0);
Calendar end = Calendar.getInstance();
end.set(2012, 0, 10, 4, 0, 0);
long startTime = d.getTimeInMillis();
long endTime = end.getTimeInMillis();
// endTime = endTime * 1000;
// startTime = startTime * 1000;
System.out.println("HOW TO SOL:VCE THIS");
System.out.println(startTime);
System.out.println(endTime);
cv.put("dtstart", startTime);
cv.put("dtend", endTime);
cv.put("rrule","FREQ=DAILY;BYDAY=MO,TU,WE,TH,FR");
// let the calendar know whether this
// event goes on all day or not
// true = 1, false = 0
cv.put("hasAlarm", 1);
Uri newEvent ;
if (Integer.parseInt(Build.VERSION.SDK) == 8 )
newEvent = cr.insert(Uri.parse("content://com.android.calendar/events"), cv);
else
newEvent = cr.insert(Uri.parse("content://com.android.calendar/events"), cv);
if (newEvent != null)
{
long id = Long.parseLong( newEvent.getLastPathSegment() );
ContentValues values = new ContentValues();
values.put( "event_id", id );
values.put( "method", 1 );
values.put( "minutes", 15 ); // 15 minuti
if (Integer.parseInt(Build.VERSION.SDK) == 8 )
cr.insert( Uri.parse( "content://com.android.calendar/reminders" ), values );
else
cr.insert( Uri.parse( "content://calendar/reminders" ), values );
}
dialog.cancel();
}
});
builder.create().show();
}
cursor.close();