Your SlideShare is downloading. ×
Adding Calendar Events – Phonegap Android plugin
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×
Saving this for later? Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime – even offline.
Text the download link to your phone
Standard text messaging rates apply

Adding Calendar Events – Phonegap Android plugin

2,782
views

Published on

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/

Published in: Technology

0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
2,782
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
12
Comments
0
Likes
0
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide

Transcript

  • 1. 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.
  • 2. 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.

×