I have managed to pass through the "main" information into a calendar intent...
however when I try to add attendees to the intent, they are not inserted. Here is the code
startCalIntent = new Intent(Intent.ACTION_EDIT);
startCalIntent.setType("vnd.android.cursor.item/event");
startCalIntent.putExtra(Events.TITLE, title);
startCalIntent.putExtra(Events.EVENT_LOCATION, location);
startCalIntent.putExtra(Events.DESCRIPTION, details);
startCalIntent.putExtra(Events.ORGANIZER, organiser);
startCalIntent.putExtra(CalendarContract.EXTRA_EVENT_BEGIN_TIME, splitDateTime(date, startTime));
startCalIntent.putExtra(CalendarContract.EXTRA_EVENT_END_TIME, splitDateTime(date, endTime));
startCalIntent.putExtra(Events.EVENT_TIMEZONE, "Europe/London");
startCalIntent.putExtra(Attendees.HAS_ATTENDEE_DATA, "1");
startCalIntent.putExtra(Attendees.ATTENDEE_NAME, "DAVE");//<---NOT WORKING
startActivity(startCalIntent);
You cannot add attendee during creating event. You need Event_ID to proceed another update on event like adding remainders, or attendees.
Note: See how this example captures the event ID after the event is
created. This is the easiest way to get an event ID. You often need
the event ID to perform other calendar operations—for example, to add
attendees or reminders to an event.
source: Android developer
you can use this code as provided in Android developer:
long eventID = 202;
...
ContentResolver cr = getContentResolver();
ContentValues values = new ContentValues();
values.put(Attendees.ATTENDEE_NAME, "Trevor");
values.put(Attendees.ATTENDEE_EMAIL, "trevor#example.com");
values.put(Attendees.ATTENDEE_RELATIONSHIP, Attendees.RELATIONSHIP_ATTENDEE);
values.put(Attendees.ATTENDEE_TYPE, Attendees.TYPE_OPTIONAL);
values.put(Attendees.ATTENDEE_STATUS, Attendees.ATTENDEE_STATUS_INVITED);
values.put(Attendees.EVENT_ID, eventID);
Uri uri = cr.insert(Attendees.CONTENT_URI, values);
Hope that may help;
Try this ..
ContentValues values = new ContentValues();
values.put("calendar_id", 1);
values.put("title", "event Name");
values.put("allDay", 0);
values.put("dtstart", cal.getTimeInMillis() + diffInhrs*60*1000); // event starts at date specified in datepicker
values.put("dtend", cal.getTimeInMillis()+ end_diff *60*1000); // ends 60 minutes from selected date
values.put("description", "event desc");
values.put("visibility", 0);
values.put("hasAlarm", 1);
Uri event = cr.insert(EVENTS_URI, values);
For more explaination plz go through this CLICK HERE
Related
I want to add the event in the calendar programmatically, and I have successfully done it. But when I call and calendar intent, It will open the calendar with event details on it. Users can modify that event before saving it.
So I want the event to be like noneditable. It will be good if it's getting added automatically. I have looked for so many solutions but nothing worked for me.
Thanks.
long calID = 3;
ContentResolver cr = getContentResolver();
ContentValues values = new ContentValues();
values.put(CalendarContract.Events.DTSTART, beginTime.getTimeInMillis());
values.put(CalendarContract.Events.ALL_DAY,false);
values.put(CalendarContract.Events.TITLE, projectName);
values.put(CalendarContract.Events.EVENT_LOCATION,projectAddress);
values.put(CalendarContract.Events.DESCRIPTION, eventDetail);
values.put(CalendarContract.Events.CALENDAR_ID, calID);
values.put(CalendarContract.Events.EVENT_TIMEZONE,"America/Los_Angeles");
values.put(CalendarContract.Events.DURATION,"+P1H");
cr.insert(CalendarContract.Events.CONTENT_URI, values);
Utility.getInstance().showSnackBar(rl_main, "Event addded to calendar
successfully!");
I am working on android application that needs phone calls to be logged on the server for personal use of course. I have broadcastreceiver registered for this purpose and I am able to detect all types of calls and their details. However, it is not possible to detect accurate outgoing call time i.e. we get to detect complete OFFHOOK time for outdoing call which is not exactly call duration talked. So only for outgoing call ended case I try to read records from the call log history. I am able to read call log history from broadcastreceiver for outgoing call ended but I don't see the entry of currently received call in the call log entry. I can see all the previous calls in the call history but not the one for which I received broadcastreceiver. I am using Gabe Sechan example from here in my code. And I try to read latest call history in outgoingcallended method like this,
ContentResolver crs = globalContext.getContentResolver();
Cursor cr = getAllCallLogs(crs);
if(cr.moveToFirst()){
duration = cr.getString(cr
.getColumnIndex(android.provider.CallLog.Calls.DURATION));
callNumber = cr.getString(cr
.getColumnIndex(android.provider.CallLog.Calls.NUMBER));
}
private Cursor getAllCallLogs(ContentResolver cr) {
// reading all data in descending order according to DATE
String strOrder = android.provider.CallLog.Calls.DATE + " DESC";
Uri callUri = Uri.parse("content://call_log/calls");
Cursor cur = cr.query(callUri, null, null, null, strOrder);
return cur;
}
But the callNumber is previous call number and not the one for which I received broadcastreciver and same is the case with the duration.
I understand that by the time I try to read call log it is not updated so how do I solve this? What am I missing?
You have to add some delay before getContentResolver(), so that table get updated. You can add either Thread.sleep() or can use handler.
public void loadCursorPostDelayed(){
final Handler handler = new Handler();
handler.postDelayed(new Runnable() {
#Override
public void run() {
ContentResolver crs = globalContext.getContentResolver();
...
}
}, 1500);
}
}
I'm trying to set several alarms with my app, and cancel them upon request.
I've read a lot of topics about the same, and went through the documentation, but it seems like it doesn't work.
Documentation says that cancel will try to find an intent that matches the one I provide with 'filterEquals'('Determine if two intents are the same for the purposes of intent resolution (filtering). That is, if their action, data, type, class, and categories are the same. This does not compare any extra data included in the intents.')
I'm providing same action, data, type, class, and category, so why does it not work?
Create alarm:
AlarmManager manager = (AlarmManager)getSystemService(Context.ALARM_SERVICE);
int interval = 30000;
Intent intent = new Intent(getApplicationContext(), Broadcast.class);
intent.putExtra("alarmTime",alarmTime);
intent.putExtra("reminder1",reminder1);
intent.putExtra("reminder2",reminder2);
intent.putExtra("title",title);
intent.putExtra("message",message);
intent.putExtra("vibrate",vibrate);
intent.putExtra("sound",sound);
intent.putExtra("name",name);
//Create _id from data input. is unique
int _id = 0;
for (char i: name.toCharArray()){
_id += Character.getNumericValue(i);
}
for (char i:title.toCharArray()){
_id += Character.getNumericValue(i);
}
for (char i:message.toCharArray()){
_id += Character.getNumericValue(i);
}
_id += (int) alarmTime.getTime();
_id += (int) reminder1.getTime();
_id += (int) reminder2.getTime();
Log.e("ALARMS", "Creating alarm with id: "+_id);
intent.setData(Uri.parse("custom://" + _id));
intent.setAction(String.valueOf(_id));
PendingIntent pendingUpdateIntent = PendingIntent.getBroadcast(getApplicationContext(), _id, intent, 0);
manager.set(AlarmManager.ELAPSED_REALTIME_WAKEUP, SystemClock.elapsedRealtime() + interval, pendingUpdateIntent);
Cancel alarm
AlarmManager manager = (AlarmManager)getSystemService(Context.ALARM_SERVICE);
Intent intent = new Intent(getApplicationContext(), Broadcast.class);
intent.putExtra("alarmTime",alarmTime);
intent.putExtra("reminder1",reminder1);
intent.putExtra("reminder2",reminder2);
intent.putExtra("title",title);
intent.putExtra("message",message);
intent.putExtra("vibrate",vibrate);
intent.putExtra("sound",sound);
intent.putExtra("name",name);
int _id = 0;
for (char i:name.toCharArray()){
_id += Character.getNumericValue(i);
}
for (char i:title.toCharArray()){
_id += Character.getNumericValue(i);
}
for (char i:message.toCharArray()){
_id += Character.getNumericValue(i);
}
_id += (int) alarmTime.getTime();
_id += (int) reminder1.getTime();
_id += (int) reminder2.getTime();
intent.setData(Uri.parse("custom://" + _id));
intent.setAction(String.valueOf(_id));
PendingIntent pendingUpdateIntent = PendingIntent.getBroadcast(getApplicationContext(), _id, intent, 0);
Log.e("ALARMS", "Cancelling alarm with id: "+_id);
// Cancel alarms
try {
manager.cancel(pendingUpdateIntent);
} catch (Exception e) {
Log.e("ALARMS", "AlarmManager update was not canceled. " + e.toString());
}
So I call 3 times the create alarm with different parameters, so my _id is different each time.
Then I call 3 times the cancel alarm and the ids generated match for each alarm upon create and cancel.
So the cancel runs but my alarms still get fired.
My alarms trigger a broadcast receiver that will output a notification per alarm.
I forgot to mention that I tried with different flags for the PendingIntent but none work (FLAG_CANCEL_CURRENT, FLAG_UPDATE_CURRENT)
Seems like I was feeding different dates to the alarms, and the _id's were different by a couple of numbers (start and finish were the same), this resulted on calling a cancel on _id values that were different and not working.
Changed the way I generate the _id to exclude the dates (which I generated with new Date()) and not it works
By bad, I didn't see it.
I would like to check in internal Android calendar for event which is currently in progress (started before current time, and ends after current time). I'm using Android 2.2
I was playing around with this piece of code - I was trying to set start time to now but this doesn't work, it returns events that started after this moment.
//building query uri
Uri.Builder builder = Uri.parse("content://com.android.calendar/instances/when").buildUpon();
long now = new Date().getTime();
ContentUris.appendId(builder, now - DateUtils.MINUTE_IN_MILLIS * 80);
ContentUris.appendId(builder, now + DateUtils.MINUTE_IN_MILLIS * 80);
Log.d("AlarmReciever", "querying for calendar with id:" + calendarId);
//interating over events
Cursor eventCursor = contentResolver.query(builder.build(), new String[] { "title" }, "Calendars._id=" + calendarId, null, null);
while (eventCursor.moveToNext()) {
final String title = eventCursor.getString(0);
Toast.makeText(context, "title: " + title, Toast.LENGTH_LONG).show();
}
I would appreciate if someone could show me how to do this correctly. Thanks!
What I want to do is to delete only the content that is saved by me in the calendar instead of all the content which is already present in the calendar. For that, I use the following code. But it will delete all the content of the calendar. So can anyone tell me how that can be prevented?
Uri CALENDAR_URI = Uri.parse("content://calendar/events");
ContentResolver cr = getContentResolver();
cr.delete(CALENDAR_URI, null, null); // Delete all
ContentValues values = new ContentValues();
values.put("calendar_id", 1);
values.put("title", this.title);
values.put("allDay", this.allDay);
values.put("dtstart", this.dtstart.toMillis(false));
values.put("dtend", this.dtend.toMillis(false));
values.put("description", this.description);
values.put("eventLocation", this.eventLocation);
values.put("visibility", this.visibility);
values.put("hasAlarm", this.hasAlarm);
cr.insert(CALENDAR_URI, values);
So what I want is to delete only that entry that is put by me.
Deleting the event
Uri EVENTS_URI = Uri.parse("content://com.android.calendar/" + "events");
ContentResolver cr = c.getContentResolver();
deleteEvent(cr, EVENTS_URI, 1);
private void deleteEvent(ContentResolver resolver, Uri eventsUri, int calendarId) {
Cursor cursor;
cursor = resolver.query(eventsUri, new String[]{ "_id" }, "calendar_id=" + calendarId, null, null);
while(cursor.moveToNext()) {
long eventId = cursor.getLong(cursor.getColumnIndex("_id"));
resolver.delete(ContentUris.withAppendedId(eventsUri, eventId), null, null);
}
cursor.close();
}
After reading the data from the Calendar just try this out..
Adding a Single-Occurrence Event to a Calendar
To add an entry to a specific calendar, we need to configure a calendar entry to insert using the ContentValues as follows:
ContentValues event = new ContentValues();
Each event needs to be tied to a specific Calendar, so the first thing you're going to want to set is the identifier of the Calendar to insert this event into:
event.put("calendar_id", calId);
We then set some of the basic information about the event, including String fields such as the event title, description and location.
event.put("title", "Event Title");
event.put("description", "Event Desc");
event.put("eventLocation", "Event Location");
There are a number of different options for configuring the time and date of an event.
We can set the event start and end information as follows:
long startTime = START_TIME_MS;
long endTime = END_TIME_MS;
event.put("dtstart", startTime);
event.put("dtend", endTime);
If we are adding a birthday or holiday, we would set the entry to be an all day event:
event.put("allDay", 1); // 0 for false, 1 for true
This information is sufficient for most entries. However, there are a number of other useful calendar entry attributes.
For example, you can set the event status to tentative (0), confirmed (1) or canceled (2):
event.put("eventStatus", 1);
You can control who can see this event by setting its visibility to default (0), confidential (1), private (2), or public (3):
event.put("visibility", 0);
You can control whether an event consumes time (can have schedule conflicts) on the calendar by setting its transparency to opaque (0) or transparent (1).
event.put("transparency", 0);
You can control whether an event triggers a reminder alarm as follows:
event.put("hasAlarm", 1); // 0 for false, 1 for true
Once the calendar event is configured correctly, we're ready to use the ContentResolver to insert the new calendar entry into the appropriate Uri for calendar events:
Uri eventsUri = Uri.parse("content://calendar/events");
Uri url = getContentResolver().insert(eventsUri, event);
The call to the insert() method contacts the Calendar content provider and attempts to insert the entry into the appropriate user Calendar. If you navigate to the Calendar application and launch it, you should see your calendar entry in the appropriate Calendar. Since the Calendar syncs, you will also see the Calendar entry online, if you're using the Google Calendar on the web.
Delete the event
private int DeleteCalendarEntry(int entryID) {
int iNumRowsDeleted = 0;
Uri eventsUri = Uri.parse(getCalendarUriBase()+"events");
Uri eventUri = ContentUris.withAppendedId(eventsUri, entryID);
iNumRowsDeleted = getContentResolver().delete(eventUri, null, null);
Log.i(DEBUG_TAG, "Deleted " + iNumRowsDeleted + " calendar entry.");
return iNumRowsDeleted;
}
Also go through this link for deleting