How to get android calendar event when I have event ID - android

Is it possible to get calendar event when I have specific ID or it is necessary to read all events and compare to my ID?
Thank you

I think is better to find it based on information of the event(title,description),because when you want to edit a speceific event meanwhile the user can delete himself your event,and create another event which might have the same ID as yours.So you will get the wrong event to edit.
So i think is safer to find your's choice event based to title or description ...
For example if you want to delete an event(android 2.2 example):
getContentResolver().delete(Uri.parse("content://com.android.calendar/events"), "title=? and description=?", new String[]{"The title of the event", "Description of the event"});

Related

Why does .event.set("fieldName", ObjectValue) not storing any data in Google Calendar API android?

I successfully intergarted Google Calendar API. I'm able to do CRUD. But now because of some requirements, I want to send some unique id to each events while creating from android app. For that I found one method called .set() this is a key value pair.
Event event = new Event()
.set("appointment_id", 55475)
.setSummary(summary)
.setLocation(location)
.setDescription(des);
But while fetching, I'm getting all data except event.get("appointment_id")
Why, even it is setting also. [If I'm doing here before executing insert like this: evetn.get("appointment_id"), I'm getting value, because this is locally I'm chocking]
I checked through debugging as well. See below:
But, I'm not getting when I'm fetching all events from Google calendar:
List<Event> items = events.getItems();
You are using the set method, but this is just an override of the com.google.api.client.json.GenericJson class, I believe this will only add this key-value to the final JSON which will be ignored by the API (as it is not an expected field).
Sincerely I don't know what is the point on creating a custom id when there is one directly integrated in calendar.
If you take a look at the insert method you can see that there is one field called id:
Opaque identifier of the event. When creating new single or recurring events, you can specify their IDs. Provided IDs must follow these rules:
characters allowed in the ID are those used in base32hex encoding, i.e. lowercase letters a-v and digits 0-9, see section 3.1.2 in RFC2938
the length of the ID must be between 5 and 1024 characters
the ID must be unique per calendar
Also in the same description for the field:
If you do not specify an ID, it will be automatically generated by the server.
My point being that if you need unique ID for events in calendar there is a built in method that will create them for you. And even if you need to supply your own id's you can do so informing this field.
Let me suggest you the official guide on event creation in which there is a more detailed view on the option you can take creating an Event.
Also look at the documentation for setId as this is the method you should be using instead of set.
Example:
Event event = new Event()
.setId("55475") // This has to be type String
.setSummary(summary)
.setLocation(location)
.setDescription(des);

Android google calendar deleting future instances of recurring event

I'm trying to delete future instances of a google calendar recurring (repeated) event pro-grammatically using content resolver.
And to do this i have updated the rRule of the event , so for example if want to delete future instances of an event starting from date 11/11/2016
i edit the rRule string to look like so:
FREQ=DAILY;UNTIL=20161111;WKST=SU
However , when viewing google calendar application i find no changes and i find the event color only has changed to black color.
Some notes to keep in mind:
1- I'm using a third party library to so :
https://github.com/EverythingMe/easy-content-providers
CalendarProvider calendarProvider = new CalendarProvider(context);
Event event = calendarProvider.getEvent(eventId);
event.rRule = "FREQ=DAILY;UNTIL=20161111;WKST=SU";
calendarProvider.update(event);
and all functionalities in this library seem to work fine.
2- While reading pro-grammatically recurring events that have a specific UNTIL date in it's rRule , i have realized that also a field in the google event called "lastDate" is updated with one hour later after the UNTIL value ,so do i have to update also this field while updating the UNTIL value in the rRule?
The problem was with the library ,
calendarProvider.update(event);
does not seems to work with all event fields!

How do I set multiple notifications using one date selection?

I need to set multiple notifications at the same time based on a list of mutiple choice questions. I will figure the radio buttons and if statements out later, for now I'm just setting the dates randomly for testing purposes.
If the user selects jan 1st and clicks a button. It will set a notification in the future with a reminder to do an activity. It also saves this information so the user can edit the details if he desires or change a few options.
This part I already have coded and it works just fine. however, It only sets a single notification currently. It is a pretty involved code consisting database, receivers, fragments, etc. that all talk to each other.
As I said, this part I have working just fine but I am not including all the code because it is seriously involved and no one would try to break it down if i drown you in a sea of code. I can certainly post specific code if someone request it.
My issue is that I need it to set a good amount of notifications at various future dates upon the button click, not just one. I need to change the notification message to a preset variable string for each additional notification event but some things like title will remain the same.
my current working code executes like this....
User Selects Jan 1 > User Clicks Button > Notification set for Feb 14 with a unique title and message set by the user and saved for future editing...
At the same time the notifications are set they are saved so the user can change the date and a few options if needed. I want only one title and a single date saved. I have the save feature already working but I need to know how to link the additional reminders to the existing saved item. Im trying to make all the data linked so that if the user deletes the saved item, all the set notifications for that file are deleted and not just the one that falls on the user selected date.
===== This is what I am trying to pull off
User Picks Some Options and Clicks A Button [I have this working already]
Upon Click of said button, the following notifications are all set in the future :
[currently it sets this notification only]
Jan 1 notification :
(title)Day Master App
(message)Happy New Year
[Im trying to figure out how to add the following notifications upon the above button click and also save this information to the existing db under the same item]
Feb 14 notification : (title)Day Master App - (message)Its V Day
March 1 notification : (title)Day Master App - (message)Spring Is Near
March 14 notification : (title)Day Master App - (message)Its probably raining
(((and we'll just pretend i finished the list...)))
I cant make the future notifications a static number because when the future notifications are set is determined by a bunch of radio button choices before the user clicks the execute button. This is going to be a pretty complex and hacky if/else novel the way I think I have to do it. Am I correct?
I have a display/edit listview that shows your saved notifications and the unique name and date the user set. This works fine currently but only sets a single notification based on user input.
I need to add some more notifications but i dont need to save them under a different item or name. I want them all under the same save item so all the notifications that were set when the button was clicked can be added and deleted as a group. There will be no option to delete certain notifications that were set. It will be all or none.
I would imagine I could just add some more variables into the existing "save notification" code? As in piggyback some more items (like all the dates and messages) for the additional notifications? do i need to write a new function for each future notification I set in order to be able to delete it?
do I need to create a new db for each additional notification that is set? A separate Adapter? Im so confused...
===
Im not looking for a code example exactly, I want to know how this would be implemented into an existing code. I realize there is probably 100 ways to code what I have described. I just need the process explained.
Please explain this to me slowly. I know im way overthinking this.
I tried to explain this as best I could, if you need clarification on something please ask. Thank You.
I have solved my problem although I could not accomplish exactly what I was trying to originally.
I managed to set the multiple notifications on a single click with different dates by simply copying the same code I used to display the single notification and simply giving each additional notification a unique ID and creating a new variables to give them individual text, future dates, separate times, etc. These variables can be easily set programmaticly or by the user when you set them up.
// On clicking the set notifications button
public void SetNotificationsButton(View v){
ReminderDatabase rb = new ReminderDatabase(this);
// Creating Original Reminder
int ID = rb.addReminder(new Reminder(mTitle,
mDate, mTime, mRepeat, mRepeatNo, mRepeatType, mActive));
// Create Feeding Notification
int FeedingID = rb.addReminder(new Reminder("Have you fed the cat today?",
mFeedingDate, mFeedingTime, mRepeat, mRepeatNo, mRepeatType, mActive));
}
//
// and just continued copy and pasting the rest of the notification events
// changing the ID for each individual notification. Without a unique ID
// the current notification will override the previous notification and
// appear to only set the last reminder.
I was not able to remove all notifications by selecting a single list item, I probably could have figured this out by grouping the notifications into a separate variable but once I realized that you can only have a maximum of 50 notifications set at any given time it seemed like overkill.
Since I have a repeat option for certain notifications I can keep my notifications set; numbers low and stay away from the 50 at a time limit while still firing a reminder to the user every day.
I found a great example for setting single notifications I used as reference.
https://github.com/blanyal/Remindly
Thank those of you who took the time to read my question.

Android - Block editable calendar event

I guess not, but just for trying. It is possible add an event programmatically and this event can't be edited anymore? The user just can delete the event, but he can't edit it, for example, he can't edit the date of event.
I think it's possible, but it's going to be complex. You should look at the Calendar Provider API and you may wish to see how the Last.fm app does things.
try to put the content value CalendarContract.Events.IS_ORGANIZER to true for the event and CalendarContract.Calendars.OWNER_ACCOUNT with the email of the user account when you create the calendar.

Android application structure issue

I'm working on application and I need some suggestions which is the best way to code it for Android. Basically it's something like event guide for a few cities. Imagine this :
I have an activity with 7 different buttons (7 different cities) and clicking on one of these buttons I'm opening a new activity where I have all months (January-December) as buttons again. If there is some event in February for example in the chosen city the button will be active and I will go to another activity where I have a list with the events. So my idea is to do it in this way :
Create one Activity with all Cities
Create one Calendar activity with all months.
When user select for example Paris, I'll send an extra via intent with an ID of the chosen city :
intent.putExtra("chosenCity", 2); //something like this
In the Calendar activity I will make active/inactive months buttons depending on that extra sent from Cities activity.
And when user chose a month I will send that chosenCity extra again to the ListViewEvents activity and populate the list view from Database (for example) depending on that extra.
So my question is : is it a good way to build an application like that? Or if it's not, which is the best way to achieve this?
Thanks in advance!
Sounds like you already know pretty much what you need to do. The only thing left is to implement it. The only thing I'll add is that your should probably store all your database and use a CursorAdapter to display them in the ListView. You can store all the events in the database and just create your select statement in such a way that it only selects the events you want to display at any given time. When using this CursorAdapter, I highly recommend you use the CursorLoader.

Categories

Resources