Make exception event from original recurring event? - android

I found that Events.CONTENT_EXCEPTION_URI (here) used for make recurring event.
It's hardly to find document or code example from internet. So I try many ways
1 Insert as SyncAdapter
ContentValues values = new ContentValues();
values.put(Events.ORIGINAL_INSTANCE_TIME, CaldavGlobalVar.getCurrentTime_());
values.put(Events.SELF_ATTENDEE_STATUS, status);
if(!username.equals("")){
values.put(Events.ORGANIZER, username);
}
if(event.getSummarry()!=null){
values.put(Events.TITLE, event.getSummarry());
}
if(event.getDescription()!=null){
values.put(Events.DESCRIPTION, event.getDescription());
}
if(event.getDateStart()!=null){
values.put(Events.DTSTART, CaldavGlobalVar.convertTIMEtomilisecond(event.getDateStart(), event.getAllDay()));
}
Uri exceptionUri = Uri. withAppendedPath(Events.CONTENT_EXCEPTION_URI, String.valueOf(event.getEventId()));
Uri syncUri = CalendarProvider.asSyncAdapter(exceptionUri, username,context.getResources().getString(R.string.ACCOUNT_TYPE));
Uri resultUri = context.getContentResolver().insert(syncUri, values);
resultUri return null, I didnot see any exception or any relation things, So I dig Android source code (from here) and find out the way they use Events.CONTENT_EXCEPTION_URI So I change
2 Insert by "ContentProviderOperation" like this, in line 1003
ContentValues values = new ContentValues();
values.put(Events.ORIGINAL_INSTANCE_TIME, CaldavGlobalVar.getCurrentTime_());
values.put(Events.SELF_ATTENDEE_STATUS, 1);
values.put(Events.STATUS, Events.STATUS_CONFIRMED);
ArrayList<ContentProviderOperation> ops = new ArrayList<ContentProviderOperation>();
Uri exceptionUri = Uri.withAppendedPath(Events.CONTENT_EXCEPTION_URI,
String.valueOf(eventId));
ops.add(ContentProviderOperation.newInsert(exceptionUri).withValues(values).build());
mHandler.startBatch(mHandler.getNextToken(), null, CalendarContract.AUTHORITY, ops, 1000);
But it show log that It installed unsuccessfully, I am so worry about that, may be Google not support it fully, I also list all Content Provider in Android, I dont has any exception uri (Events.CONTENT_EXCEPTION_URI) --content://com.android.calendar/exception
Exception throwed
java.lang.IllegalArgumentException: Unknown URL content://com.android.calendar/exception
Does anyone have experience ? Any help are appreciate :)
Kind regards

A small part of my code:
ContentValues args = new ContentValues();
args.put(CalendarContract.Events.ORIGINAL_INSTANCE_TIME, originalinstancetime);
args.put(CalendarContract.Events.STATUS, status);
Uri.Builder eventUriBuilder = CalendarContract.Events.CONTENT_EXCEPTION_URI.buildUpon();
ContentUris.appendId(eventUriBuilder, originalEventID);
try {
final Uri resultUri = context.getContentResolver().insert(eventUriBuilder.build(), args);
int eventID = Integer.parseInt(resultUri.getLastPathSegment());
} catch (Exception e) {
}

Related

When is the ANDROID Contact Group PHYSICALLY removed instead of being marked as deleted?

I am trying to permanently remove a Android Contact Group and have used the Sync parameter and it always appears the record is simply marked as deleted and not physically removed. Can anyone explain how/when, if ever, the Contract group row is deleted permanently or show a snippet of code demonstrating how to do this? The records I am trying to remove are ones that I added, so they are not Read-Only.
Linked back to https://stackoverflow.com/a/21376905/5398898
My Delete Code:
private void RemoveGroup()
{
TextView tv = (TextView) this.findViewById(R.id.helloworld);
int[] startId = {10};//{6, 7, 8, 9, 10, 11};
String groupName = "My New Contacts";
Uri mUri = ContactsContract.Groups.CONTENT_URI;
mUri.buildUpon().appendQueryParameter(ContactsContract.CALLER_IS_SYNCADAPTER, "true").build();
for (int n = 0; n < startId.length; n++) {
groupCount = startId[n];
ContentValues values = new ContentValues();
values.put(ContactsContract.Groups._ID, groupCount);
try {
getContentResolver().delete(mUri, values.toString(),null);
} catch (Exception ex) {
tv.setText(ex.getMessage());
}
}
}
Result when reading the groups:
Image can be found here http://i.stack.imgur.com/5OOfc.png
You are building the correct Uri but not using it, try like this
Uri mUri = ContactsContract.Groups.CONTENT_URI;
mUri = mUri.buildUpon().appendQueryParameter(ContactsContract.CALLER_IS_SYNCADAPTER, "true").build();

Remove and Update existing Calendar Event

I am following this gist, to insert event into Calendar
How do I update existing Calendar Event, which i have inserted earlier using below code:
public void addToCalender() throws ParseException {
......
ContentValues event = new ContentValues();
event.put(CalendarContract.Events.CALENDAR_ID, calendarId[0]);
event.put(CalendarContract.Events.TITLE, "Event Title");
event.put(CalendarContract.Events.DESCRIPTION, "Event Description");
event.put(CalendarContract.Events.EVENT_LOCATION, "Eevnt Location");
event.put(CalendarContract.Events.DTSTART, startCalTime);
event.put(CalendarContract.Events.DTEND, endCalTime);
event.put(CalendarContract.Events.STATUS, 1);
event.put(CalendarContract.Events.HAS_ALARM, 1);
event.put(CalendarContract.Events.EVENT_TIMEZONE, timeZone.getID());
Uri insertEventUri = AddEventActivity.this.getContentResolver().insert(
eventsUri, event);
ContentValues reminders = new ContentValues();
reminders.put(Reminders.EVENT_ID,
Long.parseLong(insertEventUri.getLastPathSegment()));
reminders.put(Reminders.METHOD, Reminders.METHOD_ALERT);
reminders.put(Reminders.MINUTES, 10);
AddEventActivity.this.getContentResolver().insert(remainderUri, reminders);
}
I would like to know, How do I :
1. Remove existing event
2. Update existing event
Here is how you can modify an event. Let's say its ID is eventID:
public void updateEvent(int eventID)
{
ContentResolver cr = context.getContentResolver();
Uri eventUri = ContentUris.withAppendedId(CalendarContract.Events.CONTENT_URI, eventID);
ContentValues event = new ContentValues();
event.put(CalendarContract.Events.TITLE, "new title");
event.put(CalendarContract.Events.DESCRIPTION, "My cool event!");
cr.update(eventUri, event, null, null);
}
To remove an event, you have two possibilities:
If you are a standard application:
Use the previous code and replace all the event.put by this one:
event.put(CalendarContract.Events.DELETED, 1);
If you are the SyncAdapter of the calendar and want a real deletion (The previous method just says that the event should be deleted and the one that follows must be used once the calendar is being synced :
public deleteEvent(Uri eventUri)
{
cr.delete(event, null, null);
}
Where eventUri is the Uri of the event obtained as shown previously from the event ID.
For all of the previous methods, if you get an exception about not being in a sync adapter, you can use this:
public static Uri asSyncAdapter(Uri uri, String account, String accountType)
{
return uri.buildUpon()
.appendQueryParameter(CalendarContract.CALLER_IS_SYNCADAPTER, "true")
.appendQueryParameter(CalendarContract.Calendars.ACCOUNT_NAME, account)
.appendQueryParameter(CalendarContract.Calendars.ACCOUNT_TYPE, accountType)
.build();
}
I hope this will help you.
Source: personnal code + http://developer.android.com/guide/topics/providers/calendar-provider.html
...
Outlook in fact seems to respond to the rules defined in RFC 2446
In summary you have to specify
METHOD:REQUEST and ORGANIZER:xxxxxxxx
...
Please read the original answer by Tom Carter.

Calendar I created on "com.google" on android erased after sync

I created a new calendar on android and added events.
After first sync or after a few seconds it's erasing. Can somebody help with this problem?
Code:
private void createCalendar(Context context, String accName) {
Uri calUri = CalendarContract.Calendars.CONTENT_URI;
final ContentValues v = new ContentValues();
v.put(CalendarContract.Calendars.ACCOUNT_NAME, accName);
v.put(CalendarContract.Calendars.NAME, CALENDAR_NAME);
v.put(CalendarContract.Calendars.CALENDAR_DISPLAY_NAME, CALENDAR_NAME);
v.put(CalendarContract.Calendars.ACCOUNT_TYPE, "com.google");
v.put(CalendarContract.Calendars.CALENDAR_COLOR, 0xEA8561);
v.put(CalendarContract.Calendars.CALENDAR_ACCESS_LEVEL, CalendarContract.Calendars.CAL_ACCESS_OWNER);
v.put(CalendarContract.Calendars.OWNER_ACCOUNT, accName);
v.put(CalendarContract.Calendars.SYNC_EVENTS, 1);
v.put(CalendarContract.Calendars.VISIBLE, 1);
calUri = calUri.buildUpon()
.appendQueryParameter(CalendarContract.CALLER_IS_SYNCADAPTER, "true")
.appendQueryParameter(CalendarContract.Calendars.ACCOUNT_NAME, accName)
.appendQueryParameter(CalendarContract.Calendars.ACCOUNT_TYPE, "com.google")
.build();
calUri = calUri.buildUpon().build();
final Uri result = context.getContentResolver().insert(calUri, v);
}
Unfortinately this is a known issue with the calendar API. you have only one option if you want to use the Android calendar- create the calendar as a local one and synchronize it yourself.

write in the android calendar

As part of a project, I created an android application which communicates with an online database (MySQL) to integrate the appointment has taken the online calendar.
I collect the data, converted to Json, but when the inscrires in the agenda of android mobile I encounter a probleme, here is my code : (sorry for my english )
EDIT :
public class calendrier extends Activity {
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Cursor cursor = getContentResolver()
.query(Uri.parse("content://com.android.calendar/calendars"),
new String[] { "_id", "displayName" }, "selected=1",
null, null);
if (cursor != null && cursor.moveToFirst()) {
String[] calNames = new String[cursor.getCount()];
int[] calIds = new int[cursor.getCount()];
for (int i = 0; i < calNames.length; i++) {
calIds[i] = cursor.getInt(0);
calNames[i] = cursor.getString(1);
cursor.moveToNext();
}
cursor.close();
if (calIds.length > 0) {
// we're safe here to do any further work
}
// grab calendar id from above
int cal_id = calIds[0];
// set the content value
ContentValues cv = new ContentValues();
cv.put("calendar_id", cal_id);
cv.put("title", "titre");
cv.put("description", "bla bla bla");
cv.put("eventLocation", "city");
// note: you're going to need to convert the desired date into
// milliseconds
cv.put("dtstart", System.currentTimeMillis());
cv.put("dtend", System.currentTimeMillis()
+ DateUtils.DAY_IN_MILLIS);
cv.put("allDay", 0); // true = 1, false = 0
cv.put("hasAlarm", 1);
// once desired fields are set, insert it into the table
getContentResolver().insert(
Uri.parse("content://com.android.calendar/events"), cv);
}
}
}
this code works but it asks me if I want to participate in the event when I open it and I wish he does not do
thanks
//did U include permission in your manifest.xml file
android.permission.READ_CALENDAR
android.permission.WRITE_CALENDAR
String WRITE_CALENDAR Allows an application to write (but not read) the user's calendar data.
The Uri of Calendar has changed from Android 2.2 .
Old (2.1 and before): content://calendar/
New (2.2): content://com.android.calendar/
Change your Uri to the new one.
There is no Calendar Application by default in Android. So the Uri may not work at all.
If, you are getting the first error message as "Failed to find provider info for com.android.calendar", you need to check the handset you are using to debug uses which Calendar URI.
To insert Time in Calendar event, you can use the following code example:
Calendar calendar = Calendar.getInstance();
calendar.getTimeInMillis();
cv.put("dtstart", ""+calendar.getTimeInMillis());
cv.put("dtend", ""+calendar.getTimeInMillis()+10000);

Android add contact email

I'm trying to insert a new contact into the Androids contact list. Adding a name and phone numbers works fine, but adding an email address doesn't work. My code:
//name is a string
//phone and email are string arrays
ContentValues values = new ContentValues();
values.put(People.NAME, name);
Uri newPerson = People.createPersonInMyContactsGroup(cr, values);
if (newPerson != null) {
for (i=0; i<phone.length; i++) {
Log.i("Phone",""+phone[i]);
values.clear();
Uri mobilesUri = Uri.withAppendedPath(newPerson,People.Phones.CONTENT_DIRECTORY);
values.put(People.Phones.NUMBER,phone[i]);
values.put(People.Phones.TYPE,People.Phones.TYPE_MOBILE);
Uri phonesUpdate = cr.insert(mobilesUri, values);
}
for (i=0; i<email.length; i++) {
Log.i("Email",""+email[i]);
values.clear();
Uri emailUri = Uri.withAppendedPath(newPerson,People.ContactMethods.CONTENT_DIRECTORY);
values.put(People.ContactMethods.KIND,People.ContactMethods.KIND_EMAIL);
values.put(People.ContactMethods.TYPE,People.ContactMethods.TYPE_HOME);
values.put(People.ContactMethods.DATA,email[i]);
Uri emailUpdate = cr.insert(emailUri, values);
}
}
I get an error in this line:
values.put(People.ContactMethods.KIND,People.ContactMethods.KIND_EMAIL);
of
error: cannot find symbol
Edit: I forgot to mention I use Xcode/Ant and revision 8 (2.2 (Froyo)).
This works for me:
values.put(People.ContactMethods.KIND, Contacts.KIND_EMAIL);
which I got from the well-hidden (at least for Contact programming info):
developer.android.com: Content Providers: Modifying data in a provider
You may get some help from this example: Android Developers - ContactOperations.

Categories

Resources