I'm building an application for students to manage the courses of a university.
Now I would like to synchronize the events (an event has a date and time and a brief description) with the google calendar of Android.
I took a look at the samplesync adapter from the Android sample, but I didn't find it very useful for the calendar.
The sync of the app should be enabled and disabled from the settings of the app with a checkbox.
Does anyone has some sample code that can be useful??
Use android.preference.PreferenceActivity to make your preference page.
Ensure that your app updates the checkbox on the preference page with the value from the system before it opens. (The setting may have been changed in the Accounts & Sync system control panel.) Use ContentResolver.getSyncAutomatically(Account account, String authority) to read the system value
Command the system to match the PreferenceActivity setting using ContentResolver.setSyncAutomatically(Account account, String authority, boolean sync) --
Note that you can't control sync on a provider -- you control it for an account/provider pair. Your app will need to keep a copy of the Account it is set to use so it can pass it in these calls.
Related
I'm developing an Application using Firebase analytics, authentication and DB services.
I need to save some preferences and some settings, related to the user.
Most of them are managed in a "SettingsActivity" which is similar to the sample one provided by Android Studio, but with this configuration if the user changes the device, those preferences are lost.
The app should provide a customizable experience for each user. To achieve this I'd like my preferences to be saved on Firebase insted of in local Preferences.
How can I achieve this without have to change too much my app structure?
EDIT:
Here's an example:
The user download my App on first device (Dev-A), he sign up, then he goes to settings and set first setting from A to B, and second setting from A to D.
Then he decide to download my App on a second device (Dev-B), he log in, then he goes to settings.
On Dev-A, first setting is set to B and second setting is set to D.
On Dev-B, first setting is set to A and second setting is set to A.
You will need to store this information in Firebase Database.
Use the user'd UID you get from Firebase Auth in the Database to store the settings.
The data should be under '/users/{uid}'
This way, you will persist all user specific data across devices. (Since the same UID will be presented to same authentication account)
Check this link in Firebase documentation to set the database security
You should try this library:
A implementation of SharedPreferences which syncs with Firebase database to keep your SharedPreferences in sync between multiple devices of one user and/or to back them up for app re-installs!
I decided to use Google Calendar API for my running app. I need to have some default public events in my calendar, this way anybody who is logged with different Google accounts could see them.
The questions is, what is the easiest way to store events, that everybody, who is logged from different accounts could see them?Maybe I need to create main events calendar and share to other local calendars?
You may want to check the use of Extended Properties which makes it easy to store application-specific data for an event without having to utilize an external database.
You can have the shared properties which are visible and editable by all attendees of an event. This property is shown regardless of the calendarId used in the request.
And to add or update events, using patch requests is the preferred method, as it allows you to manipulate some properties while leaving others untouched. Adding a new property with the same key will overwrite any existing properties with the same key.
Please visit the given link for a more detailed information.
I have created an application which contains certain date option.
Now suppose on some date I have write notes my app.
Now when I press my submit button, these notes are save in the device calendar.
So, is it possible to save the data that you used in your application directly in the device calendar based on the date you have selected for saving data? Moreover, when I delete my data from the app, the data saved in the device calendar is also deleted.
Take a look at this link: http://code.google.com/apis/calendar/data/2.0/developers_guide.html
There is a Java library for API version 2.0. Try using that to modify a particular user's Google Calendar.
You can find the current user's e-mail ID (Google account) from this question: How can you get an Android user's email address?
Update:
Here is a sequence that might work:
Authentication - The first step would be to have the user login into his Google account. Link: http://code.google.com/apis/accounts/docs/AuthForInstalledApps.html
List calendars - Next, ask the user to select which calendar he wants to use. Check here to see how to get list of calendars: http://code.google.com/apis/calendar/data/2.0/developers_guide_java.html#RetrievingCalendars
Add Event - Finally, add the event to the selected calendar: http://code.google.com/apis/calendar/data/2.0/developers_guide_java.html#CreatingSingle
Obviously there might be steps I have missed. Do try these out and read the documentation to see if some steps are required in between
To modify a user's Google Calendar, use the Google Calendar GData API.
i have an application in which i need to sync the events that i get from an xml to the default calendar provided in the users phone.
for the above i have referred this tutorial.But over here the first it is required to get the id and name of all the available calendars in the users phone... i don't know the id and name of the default calendar in the users phone....which calendar should i use to put events in?
i am not putting the code here as the code is present in the link given.
thank you in advance.
You can't know ahead of time. There is no system setting for the default calendar. You must account for this in your application by allowing the user to select the calendar or coming up with your own way of determining the "default".
Be careful not to rely on the persistence of any calendar because if they are Google calendars they will come and go with corresponding changes in the cloud.
Is there a way to change the sync settings of a Gmail account programmatically with an Android app? For instance, I'd like to enable/disable syncing of a Gmail account from my app, without the user having to do anything.
I took a look at AccountManager, but that doesn't seem to be the right place to look.
You can change it through the API using ContentResolver.setSyncAutomatically(Account account, String authority, boolean sync). You need to get a handle to the account in question (usually through the AccountManager class...) and you'll need to lookup the content authority string. The latter you can get from android.Provider.xxxContract (ContactsContract for example...)
I can tell you:
Generally, sync is controlled via the BACKGROUND_DATA setting in Settings.Secure, which cannot be modified by applications
The Gmail application is not part of the SDK and so exposes no APIs