I want to get calendar event updates (when a new event is added or an existing event is deleted ) on android 2.2 devices ?
In other words, my program wants to get notifications for any calendar event changes
Anyone has any thoughts regarding how to do this?
whenever the Calendar update is made,u can get notification by using Content Observer,u have to register first observer using
this.getContentResolver().registerContentObserver(uri, true, observer);
where uri is the the calendar uri like "content://com.android.calendar/events" and observer is the object of the class extending Content Observer which overrides on change method,invoked when the change occurs
you have to notify this observer using
this.getContentResolver().notifyChange(eventsUri, null)
wherever u r performing changes like in read or delete operation of the calendar
Related
I am investigating the use of GraphStream on Android using
api 'com.github.graphstream:gs-ui-android:2.0-alpha'
api 'com.github.graphstream:gs-core:2.0-alpha'
I have managed to construct and display my Graph fine,
However I cannot see how to listen for user interactions on the nodes within my graph.
I need to display a Dialog when any node is clicked on by the user and display the specific nodes information.
I've tried setting a Listener on the org.graphstream.ui.android_viewer.AndroidViewer, however I never received any callbacks
I can drag the displayed nodes around the screen so I know there are default listeners, how to I add my own listeners though?
You can implement ViewerListener with the ViewerPipe like this :
ViewerPipe pipe = fragment.getViewer().newViewerPipe();
pipe.addAttributeSink( graph );
pipe.addViewerListener( this ); // this or any class which implements ViewerListener
pipe.pump();
You can get an exemple here : https://github.com/graphstream/gs-ui-android-test/blob/master/app/src/main/java/ui/graphstream/org/gs_ui_androidtestFull/Activity_TestArrows.java
And here to understand how ViewerPipe works : http://graphstream-project.org/doc/Tutorials/Graph-Visualisation/
According Firebase Android SDK Release Notes with 9.8 update we have screen tracking support with android screens and activities... The documentation says that this event works like that:
mFirebaseAnalytics.setCurrentScreen(activity,class_name,class_override_name);
In my case, I don't need overrides class name and I send null value... But i'm waiting 48h and my firebase analytics console doesn't show info about this event, any ideas?
Thanks in advance!
Another very important thing that I've noticed only after two days of intensive struggling: the setCurrentScreen method MUST be called on the UI thread.
I was only able to see that after looking for a light in the Firebase decompiled code:
#MainThread
#Keep
public final void setCurrentScreen(#NonNull Activity var1, #Size(min = 1L,max = 36L) #Nullable String var2, #Size(min = 1L,max = 36L) #Nullable String var3) {
//...
}
Whenever this method is called a event of type screen_view is logged.
And keep in mind the Firebase size restrictions. The maximum size of a screen name is 36 characters long.
First I had the same question: where is my event with current screen name on the Firebase dashboard?
I've called method mFirebaseAnalytics.setCurrentScreen(this, "MainActivity", null); with no result.
Thanks to the comment by Benoit I realized that this method indicates the value of implicit parameter that is automatically attached to any event you send.
That means it's not independent event, it's a parameter that will stick to all your events since you set it.
This will be useful if you have changing screens within single Activity. For example when you have multiple fragments with one hosting Activity. And you call this method in each fragment in onResume().
If you want to have distinct metric with the name of your screen - fire explicitly a new event for that.
Bundle params = new Bundle();
params.putString(FirebaseAnalytics.Param.ITEM_CATEGORY, "screen");
params.putString(FirebaseAnalytics.Param.ITEM_NAME, "MainActivity");
mFirebaseAnalytics.logEvent(FirebaseAnalytics.Event.VIEW_ITEM, params);
val bundle = Bundle()
bundle.putString(FirebaseAnalytics.Param.SCREEN_NAME, "YOUR SCREEN NAME")
mFirebaseAnalytics.logEvent(FirebaseAnalytics.Event.SCREEN_VIEW, bundle)
Also Firebase Analytic's screen tracking is automatic. No need for explicit separate event tracking.
Sets the current screen name, which specifies the current visual context in your app. This helps identify the areas in your app where users spend their time and how they interact with your app.
Note that screen reporting is enabled automatically and records the class name of the current Activity for you without requiring you to call this function. The class name can optionally be overridden by calling this function in the onResume callback of your Activity and specifying the screenClassOverride parameter.
If your app does not use a distinct Activity for each screen, you should call this function and specify a distinct screenName each time a new screen is presented to the user.
The name and classOverride remain in effect until the current Activity changes or a new call to setCurrentScreen is made. I will try to add this method to onResume Method. I do not know the result but i will share my experience.
firebaseAnalytics.setCurrentScreen(activity,screeenName,activity.getClass().getSimpleName());
firebaseAnalytics.setMinimumSessionDuration(100L);
params = new Bundle();
params.putString(FirebaseAnalytics.Param.ITEM_CATEGORY, "screen");
params.putString(FirebaseAnalytics.Param.ITEM_NAME, screeenName);
firebaseAnalytics.logEvent(FirebaseAnalytics.Event.VIEW_ITEM, params);
Try using setCurrentScreen as well as manual event fire as firebase doesn't send data immediately to the console...but if event is fired up..all the remaining data is sent to firebase..
Just call that method in onResume(), and check the tracking through DebugView. it worked for me.
Check out the documentation.
When I create a Google Calendar event and attach extended property to it, all is working as expected - both event and its extended property get synced so they can be accessed from different devices. Here is the code:
// create event with extended property
ContentValues values = new ContentValues();
...
values.put(CalendarContract.Events.HAS_EXTENDED_PROPERTIES, 1);
Uri eventURI = contentResolver.insert(CalendarContract.Events.CONTENT_URI, values);
long eventID = Long.parseLong(eventURI.getLastPathSegment());
Uri extendedPropertyURI = CalendarContract.ExtendedProperties.CONTENT_URI;
extendedPropertyURI = extendedPropertyURI.buildUpon()
.appendQueryParameter(CalendarContract.CALLER_IS_SYNCADAPTER, "true")
.appendQueryParameter(CalendarContract.Events.ACCOUNT_NAME, "...")
.appendQueryParameter(CalendarContract.Events.ACCOUNT_TYPE, "com.google").build();
ContentValues extendedValues = new ContentValues();
extendedValues.put(CalendarContract.ExtendedProperties.EVENT_ID, eventID);
extendedValues.put(CalendarContract.ExtendedProperties.NAME, "name");
extendedValues.put(CalendarContract.ExtendedProperties.VALUE, "valueA");
contentResolver.insert(extendedPropertyURI, extendedValues);
Now I want to update my extended property, let's say replace "valueA" with "valueB", here is what I do:
// update extended property
int propertyID = 123; // got this ID from CalendarContract.ExtendedProperties._ID, let me omit the code
ContentValues updatedValues = new ContentValues();
updatedValues.put(CalendarContract.ExtendedProperties.VALUE, "valueB");
Uri updateUri = ContentUris.withAppendedId(extendedPropertyURI, propertyID);
contentResolver.update(updateUri, updatedValues, null, null);
The extended property value gets updated successfully, I can see "valueB" on the device where the update has been executed. But it never syncs with Google Calendar server so other devices always show "valueA". I can observe the same behavior when I am trying to add another extended property to the same event - I can see both extended properties on current device only. New extended property never gets synced.
Can anyone please help to understand what I am doing wrong? I need to be able to add multiple extended properties to an event as well as edit these properties later.
P.S. Instead of attaching one single initial extended property, I could attach multiple extended properties to a new event in a loop, they all will be synced across devices successfully:
for (int i = 0; i < 10; i ++) {
ContentValues extendedValues = new ContentValues();
extendedValues.put(CalendarContract.ExtendedProperties.EVENT_ID, eventID);
extendedValues.put(CalendarContract.ExtendedProperties.NAME, "name");
extendedValues.put(CalendarContract.ExtendedProperties.VALUE, "value" + i);
contentResolver.insert(extendedPropertyURI, extendedValues);
}
So the syncing issue only occurs when I am trying to update an existing property or add (not at same time in a loop!) a new property to an event which already has "initial" extended properties.
The explanation is simple. All changes made by a sync adapter (including inserting/updating the extended properties) are not being synced with Google servers automatically by standard Android syncing mechanism. So if you need to sync the extended property local change, you need to make the related local event dirty (not by setting CalendarContract.Events.DIRTY=1 as it also requires using a sync adapter; running ContentResolver.insert/update without any actual changes is enough). As the event is dirty now and the event change does not come from a sync adapter, Android will automatically sync both the event and its extended properties soon.
It is important to update the local event before updating its extended properties. If you update the extended properties first, the change will be lost after Android completes syncing.
You may use 'Incremental sync' to perform repeatedly and updates the client with all the changes that happened ever since the previous sync. To do this, you need to perform a list request with your most recent sync token specified in the syncToken field.
Original query
GET /calendars/primary/events?maxResults=10&singleEvents=true&syncToken=CPDAlvWDx70CEPDAlvWDx
// Result contains the following
"nextPageToken":"CiAKGjBpNDd2Nmp2Zml2cXRwYjBpOXA",
Retrieving next page
GET /calendars/primary/events?maxResults=10&singleEvents=true&syncToken=CPDAlvWDx70CEPDAlvWDx&pageT
For more details regarding Incremental sync, follow this link: https://developers.google.com/google-apps/calendar/v3/sync#incremental_sync
Is it possible to get the selected event's result to Activity using Google calendar?
I'm using startActivityForResult to open the google calendar from my application, I would like get the selected event's details in my application on onActivityForResult method. Is it possible to override the select event in google calendar?
You can use the Google Calendar API to find and view public calendar events.
The Calendar API lets you display, create and modify calendar events as well as work with many other calendar-related objects, such as calendars or access controls.
GET https://www.googleapis.com/calendar/v3/calendars/calendarId/events
import com.google.api.services.calendar.Calendar;
import com.google.api.services.calendar.model.Event;
// ...
// Initialize Calendar service with valid OAuth credentials
Calendar service = new Calendar.Builder(httpTransport, jsonFactory, credentials)
.setApplicationName("applicationName").build();
// Retrieve an event
Event event = service.events().get('primary', "eventId").execute();
System.out.println(event.getSummary());
I believe you might find Google Calendar API really useful.
Reference Link https://developers.google.com/google-apps/calendar/v3/reference/events
This might be help you.Good Luck
I can add and delete a new recurring event, but how can I edit/delete one event in a recurring event using the new Android Calendar API? And if it is possible how do I update a reminder on one event?
Regards Daniel
Maybe this will help:
// First retrieve the instances from the API.
Events instances = service.events().instances("primary", "recurringEventId").execute();
// Select the instance to edit
Event instance = instances.getItems().get(0);
if(youWantToCancel) {
instance.setStatus("canceled");
instance.setReminders(yourReminders);
Event updatedInstance = service.events().update("primary", instance.getId(), instance).execute();
}
if(youWantToDelete){
instance.setId("ToBeDeleted")
service.events().delete("primary", instance.getId()).execute();
}
If you want to delete multiple events within a recurrence, simply set the ids to some obvious string like "ToBeDeleted" and perform: service.events().delete("primary",
"ToBeDeleted").execute();
See docs