Add calendar event in Android app

I am writing an application that should record events in a calendar in the background, without user input after installing the application. This means that the methods in which the event is generated using Intents is not what I want.

I found this code on a website, but it does not work:

long start = 1297512000; // 2011-02-12 12h00 long end = 1297515600; // 2011-02-12 13h00 String title = "TEST ENTRY - DELETE ME!!"; ContentValues cvEvent = new ContentValues(); cvEvent.put("calendar_id", 1); cvEvent.put("title", title); cvEvent.put("dtstart", start ); //cvEvent.put("hasAlarm", 1); cvEvent.put("dtend", end); getContentResolver().insert(Uri.parse("content://com.android.calendar/events"), cvEvent); 

Now, before anyone enters the "Google HIGHLY recommend you not to use this method" or the like, I already know that.

Has anyone got this job? I use Gingerbread on my device, so this can cause problems!

The only alternative I discovered is to use the GData APIs, but then I need to go through authentication, and therefore it is better ... there are applications that do not need authentication, so they should use this too! :)

If anyone can help please!

Thanks neil

+4
source share
2 answers

There was a problem with conversion dates. I ended the date in the 1970s, but was expecting a date in February 2011.

Using another era converter showed that I had 3 missing 0.

+1
source

I had an application that did this, but both the HTC Sense and Motorola Motoblur interfaces violated this feature on many phones, without any fixes I could ever find. It’s a real shame that Google cannot pin these APIs and make them available on all devices. This is similar to the basic functionality that should only be in the SDK of a mobile device. I know him there in the Blackberry SDK.

I would LOVE to be able to do this, so if you find a way, send it here so I can see it. However, I would caution against this for a long time, as I just don't think you can get this to work on anything except a small subset of Android devices.

0
source

Source: https://habr.com/ru/post/1339371/


All Articles