• Share
  • Email
  • Embed
  • Like
  • Save
  • Private Content
Adding Calendar Events – Phonegap Android plugin
 

Adding Calendar Events – Phonegap Android plugin

on

  • 3,037 views

Alright, I worked on this sometime back and I will share this with you. I was looking to programmatically add events to the native Android calendar from a Phonegap android app. There is not an ...

Alright, I worked on this sometime back and I will share this with you. I was looking to programmatically add events to the native Android calendar from a Phonegap android app. There is not an official plugin that is available as of now. So I wrote a custom workaround for this. Again, I am not a Java developer and there might be better ways of writing the plugin code. But just wanted to share the code, and any feedback would just be appreciated.
For the full post download this file or visit the actual blog post link: http://jbkflex.wordpress.com/2013/02/12/adding-calendar-events-phonegap-android-plugin/

Statistics

Views

Total Views
3,037
Views on SlideShare
3,037
Embed Views
0

Actions

Likes
0
Downloads
10
Comments
0

0 Embeds 0

No embeds

Accessibility

Categories

Upload Details

Uploaded via as Microsoft Word

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

    Adding Calendar Events – Phonegap Android plugin Adding Calendar Events – Phonegap Android plugin Document Transcript

    • Adding Calendar Events – PhonegapAndroid pluginFor the full blog post visit : http://jbkflex.wordpress.com/2013/02/12/adding-calendar-events-phonegap-android-plugin/Alright, I worked on this sometime back and I will share this with you. I was looking toprogrammatically add events to the native Android calendar from a Phonegap android app.There is not an official plugin that is available as of now. So I wrote a custom workaround forthis. Again, I am not a Java developer and there might be better ways of writing the plugin code.But just wanted to share the code, and any feedback would just be appreciated.Alright, let’s get started. So, there are two files that I developed. One isthe CalendarEventPlugin.java file which has the plugin’s JAVA code. The other one isthe CalendarEventPlugin.js file which is the javascript interface of the plugin. At this point, ifyou are not sure of what goes into writing a custom Phonegap plugin for Android, then youmight want to have a look atthis. I am using Phonegap 2.2.0 for my purpose. There has beennewer version of Phoengap that is available now, 2.4.0 being the latest at the time of writing. Soyou can use the latest version as well, but do check the documentation once, there might besome changes.Check the two files out. I have inline comments that will help you to understand. Rest, is verysimple to grasp. Now let’s check how to use and implement this plugin into your PhonegapAndroid project.1) Firstly you have to add these two files to your Phonegap Android project. Addthe CalendarEventPlugin.js file insideassets/www/ folder and provide a reference to it inyour index.html file, like this<script type="text/javascript" charset="utf-8"src="CalendarEventPlugin.js"></script>2) Then create a directory inside your project’s src folder that matches the package nameof CalendarEventPlugin.java class. For our case make a directory– /org/apache/cordova/plugin inside src and then paste CalendarEventPlugin.java fileinside it. If you change the package name, make sure to change the directory structure as well.The package name can be found at the top of CalendarEventPlugin.java file.
    • 3) Next thing to do is to register the plugin in the config file – open res/xml/config.xml andthen add the plugin details given below to the <plugins></plugins> section of the XML file.The name attribute is the Java class name and the value is the path of the class. This shouldmatch the package name.<plugin name="CalendarEventPlugin"value="org.apache.cordova.plugin.CalendarEventPlugin"/>4) And then call the plugin inside your javascript (your script.js file or so) code like this. (You cancall this inside a button click handler or so), window.addcalendareventplugin(function(val){ alert(val); //once success message come and you have tested it, you canremove this alert. });Once everything runs fine, you will see that when you click a button or so in your demo app andit calls the callback function in step 4, the native Calendar Add event is popped up with valuesalready set in it (which you can change in the java file of the plugin). From there on its just thenormal way of adding events to Calendar.Hope this helps!!Note• I have tried this on an Android 4.0 device (Galaxy S3) and it works. I have not reallytried this on lower Android versions.• Unfortunately I have not tried this for an iOS device and do not have any idea on this.