I have an App which shows special Days. I want to integrate them into the calendar.
The events are static, they don't change, so I don't have to update the calendar very often.
I first thought of creating a local calendar and add the events, but new android versions (since 2.3?) seem not to support that; to implement I would have to create a Calendar Provider.
I saw this project on github: https://github.com/dschuermann/birthday-adapter. It is very complicated; its main use is adding the birthdays of the contacts to a new calendar.
There is lots of code, much of which I don't think I need. Do I really need to register to android's account manager to integrate a Calendar Provider? I just need a new Calendar with my event...
Would it be easier to take the user's default Calendar and add all the Events there? I could add some identifiers to the description, to be able to remove the events if the user doesn't want them.
Any tips, tutorials, or further readings are appreciated.
Metin Kale
You can create events in your device calendar via Intent. I think it could be useful for you.
public long addEventToCalender(ContentResolver cr, String title, String addInfo, String place, int status,
long startDate, boolean isRemind,long endDate) {
String eventUriStr = "content://com.android.calendar/events";
ContentValues event = new ContentValues();
// id, We need to choose from our mobile for primary its 1
event.put("calendar_id", 1);
event.put("title", title);
event.put("description", addInfo);
event.put("eventLocation", place);
event.put("eventTimezone", "UTC/GMT +2:00");
// For next 1hr
event.put("dtstart", startDate);
event.put("dtend", endDate);
//If it is bithday alarm or such kind (which should remind me for whole day) 0 for false, 1 for true
// values.put("allDay", 1);
// event.put("eventStatus", status);
event.put("hasAlarm", 1);
Uri eventUri = cr.insert(Uri.parse(eventUriStr), event);
long eventID = Long.parseLong(eventUri.getLastPathSegment());
if (isRemind) {
String reminderUriString = "content://com.android.calendar/reminders";
ContentValues reminderValues = new ContentValues();
reminderValues.put("event_id", eventID);
// Default value of the system. Minutes is a integer
reminderValues.put("minutes", 5);
// Alert Methods: Default(0), Alert(1), Email(2), SMS(3)
reminderValues.put("method", 1);
cr.insert(Uri.parse(reminderUriString), reminderValues); //Uri reminderUri =
}
return eventID;
}
For more information visit http://developer.android.com/reference/java/util/Calendar.html
In this reply you how to get contacts and birthdays.
Android Applicaiton - How to get birthday of a contact
and this library will offer you a powerful and flexible schedule so you can use
Caldroid Library
Related
I am developing a spring mvc project where a notification will send to user mobile.User will select a datetime at format 'yyyy-MM-dd HH:mm' from frontend and save it to the database.when system time reach that time a notification will be send to the user mobile .
I created scheduler like this
#Component
public class NotificationScheduler extends BaseService {
#Scheduled(fixedRate = 300000)
public void sendNotification() {
Date currentDate = new Date();
System.err.println("HHHHHHHHHKKKKKK");
List<ImageInfo> listImageInfo = imageInfoDao.getImageOfParticularDate(currentDate);
}
}
this is my dao function which run a wuery to database
public List getImageOfParticularDate(Date date) {
session = getSession();
session.beginTransaction();
List<ImageInfo> imageInfoList = session.createQuery("select img from ImageInfo img where img.publishedTime =:publishedTime ").setParameter("publishedTime", date).list();
session.getTransaction().commit();
return imageInfoList;
}
this code is checking repeatedly at 5 min interval whether system time equal to publish time.if it is equal then a notification will be sent.I used Date type in model and Date type column in database. I want to know my approach is right or wrong because i can not get desire output.
Why don't you use a debug mode? Change, your the time rate you use in order to not wait too much, but I think you could determine that yourself, could you?
I am developing an application which reads all the events from the calendar.ics file and then display all the events. My code works fine with individual events and i am able to extract all the events from the file because it contains all the events.
But when i create recurring events then i can't get all the events except for the first one, because calendar.ics file contains "RRULE" instead of all the events.
I have tried "rfc2445.jar" but it didn't work or maybe i don't know exactly how to use it...
Is there any library/code/method/function anything which could help me to parse and display all the events?
CalendarBuilder builder = new CalendarBuilder();
Calendar calendar = null;
calendar = builder.build(file);
Log.d("RRULE 1: ", component.getProperty("RRULE").getName());
Log.d("RRULE 2: ", component.getProperty("RRULE").getValue());
Log.d("RRULE 3: DTSTART: ",component.getProperty("DTSTART").getValue());
Log.d("RRULE 4: DTEND: ", component.getProperty("DTEND").getValue());
.......
above is the snippet of my code and i got the following results
D/RRULE 1:: RRULE
D/RRULE 2:: FREQ=DAILY;COUNT=184
D/RRULE 3: DTSTART:: 20160701T170000
D/RRULE 4: DTEND:: 20160701T200000
I don't know how to parse all the events from FREQ ?
You can use our library lib-recur.
The (very) basic usage (not accounting for time zones) would be as follows:
RecurrenceRule rule = new RecurrenceRule(component.getProperty("RRULE").getValue());
DateTime start = DateTime.parse(component.getProperty("DTSTART").getValue());
int maxInstances = 100; // limit instances for rules that recur forever
RecurrenceRuleIterator it = rule.iterator(start);
while (it.hasNext() && (!rule.isInfinite() || maxInstances-- > 0))
{
DateTime nextInstance = it.nextDateTime();
// do something with nextInstance
}
The library also supports multiple RRULEs, EXRULEs, EXDATEs, RDATEs and time zones.
I'm using the Domino Java API to query a database on a remote server. The server is processing the documents, and I'm trying to get their status. However, when I create the session, and run a query, even if I loop and check again every 30 seconds, my code will never see those documents update- it only sees the status at the time it created the first query. I have a few more loops, but the basic code outline is below- can someone tell me what I'm doing wrong?
Is there a way to update the current Database view from the Java API? The databases are not full text indexed, and cannot be due to outside constraints.
public static boolean queryDatabase(String adminFilePath, String targetItem)
NotesThread.sinitThread();
Session session =NotesFactory.createSession((String) null, (String) null, (String) null);
Registration Reg = s.createRegistration();
Reg.switchToID(adminFilePath, password);
DocumentCollection dc = getRecentDocsFromDB(session);
numResults=dc.getCount();
if (numResults > 0) {
//loop through documents to find what I'm looking for
//if the documents contain "done", finish, else:
Thread.sleep(60000);
session.recycle();
session=SessionFactory.newSession(adminFilePath, "password");
dc = getRecentDocsFromDB(session);
found = searchDocumentCollection(dc, targetItem);
//this is essentially doing the same thing again- create a session, get docs made in the
//past day or so, and loop through looking for the ones I need.
}
private static DocumentCollection getRecentDocsFromDB(Session session){
Database db = SessionFactory.openDatabase(session, server, database);
Calendar cal = Calendar.getInstance();
cal.add(Calendar.DATE, -1);
DateTime dt = session.createDateTime(cal);
DocumentCollection dc = searchNotesDBUsingDate(session, db,"Form=\"event\"", dt);
}
public static DocumentCollection searchNotesDBUsingDate(Session session,
Database database, String query, DateTime dt) throws NotesException {
DocumentCollection dc = null;
dc = database.search(query, dt);
return dc;
}
I've updated the code with a session.recycle() call. (Thanks for the suggestion!) In testing, it's not having any effect- the code is working for the first document, but then never sees a second document being called.
It's insane, because it seems to be caching the session anyway!
I tried to reproduce the problem, but I wasn't able to. In my tests, Database.search() always returns the latest documents -- even if a document is added after the database is opened. I suspect there is a subtle problem in your code (perhaps what Richard Schwartz suggested in his comment).
It may or may not be relevant, but I wasn't able to compile your version of getRecentDocsFromDB() because I don't have a SessionFactory class. My version just uses Session.getDatabase() like so:
private static DocumentCollection getRecentDocsFromDB(Session session, String server, String database) throws NotesException {
Database db = session.getDatabase(server, database);
Calendar cal = Calendar.getInstance();
cal.add(Calendar.DATE, -1);
DateTime dt = session.createDateTime(cal);
DocumentCollection dc = searchNotesDBUsingDate(session, db,"Form=\"event\"", dt);
return dc;
}
Also, as Richard mentioned, you are not reading a view. You are searching the database for all documents created (or modified) by the "event" form in the last 24 hours. And you are doing this in a tight loop. Even if you get it to work, this approach isn't the best for production. You might want to research the use of lotus.domino.View and lotus.domino.ViewNavigator.
How to pass the mail id of the calendar that to be synchronized into the create event through email?
I have a spinner that shows the list of accounts to be synchronized as below picture. Now, as usual passing title,description to create event in calendar application, i use following code.
ContentValues values = new ContentValues();
values.put("calendar_id", 1);
values.put("title", title1);
values.put("allDay", 0);
values.put("dtstart", settime);
values.put("dtend", cal.getTimeInMillis()+60*60*1000);
values.put("description", desc1);
values.put("???????", mail_id);
values.put("???????", participant_mail_id);
values.put("visibility", 0);
values.put("hasAlarm", 1);
event = cr.insert(EVENTS_URI, values);
What should i use to pass the key to insert email id and participant id? Any Help is really appreciated. My screen shot goes below.
How to pass the mail id of the calendar that to be synchronized
The event is linked to a calendar by the "calendar_id". To get the "calendar_id" you should query for all the user's calendars and then search results for name in which you are interested. Here is a tutorial which should help: Working with the Android Calendar
Alternatively, you can create an event and then let the user choose to which Calendar the event should be added: Adding Calendar event through Intent
I have search all over, and I have found bits and pieces on adding events, for .net or php, but not java.
So how do you add events to a google calendar that was created by your program.
Heres what I have
I have is
CalendarEntry calendar, returned from when I created the calendar.
Entry entry, which is a valid event to be inserted in the calendar I created.
CalendarService service, which is a valid calendar service.
So based on the calendar variable, I want to generate a url to insert the event at, by calling
service.insert(url, entry);
I happened to find an answer from here http://www.danwalmsley.com/2008/09/23/free-sms-service-notifications-using-google-calendar/
String postUrlString = calendarEntry.getLink("alternate", "application/atom+xml").getHref();
Seems to work!
From the doc:
URL postURL = new URL("http://www.google.com/calendar/feeds/root#gmail.com/private/full");
CalendarEventEntry myEvent = new CalendarEventEntry();
//Set the title and description
myEvent.setTitle(new PlainTextConstruct("Pi Day Party"));
myEvent.setContent(new PlainTextConstruct("I am throwing a Pi Day Party!"));
//Create DateTime events and create a When object to hold them, then add
//the When event to the event
DateTime startTime = DateTime.parseDateTime("2007-03-14T15:00:00-08:00");
DateTime endTime = DateTime.parseDateTime("2007-03-14T17:00:00-08:00");
When eventTimes = new When();
eventTimes.setStartTime(startTime);
eventTimes.setEndTime(endTime);
myEvent.addTime(eventTimes);
// POST the request and receive the response:
CalendarEventEntry insertedEntry = myService.insert(postURL, myEvent);
And if you already have a CalendarEntry (not tested):
/* CalendarEntry calendar = ...; CalendarEventEntry myEvent = ... */
Service myService = calendar.getService();
myService.insert(new URL(calendar.getEditLink().getHref()), yourEvent)
You can use the Google's Data API for creating events. You can download the java library from here. The Developer's guide can help you get started with using the library.
Here the documentation on creating events: http://code.google.com/apis/calendar/data/2.0/developers_guide_java.html#CreatingEvents