Firefoxos London Meetup February 2014: Hands on Web Activities

422 views

Published on

Tutorial with examples on how to use and define Web Activities in Firefox OS

Published in: Technology
0 Comments
2 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
422
On SlideShare
0
From Embeds
0
Number of Embeds
2
Actions
Shares
0
Downloads
9
Comments
0
Likes
2
Embeds 0
No embeds

No notes for slide

Firefoxos London Meetup February 2014: Hands on Web Activities

  1. 1. FIREFOX OS LONDON MEETUP FEBRUARY 2014 ! Hands on Web Activities
  2. 2. WELCOME! Today we are going to have a practical session around ! Web Activities ! (and the new app manager!)
  3. 3. WHAT ARE WEB ACTIVITIES? Web activities are one way for applications to interact which each other. We delegate a functionality on a different application and wait for the result.
  4. 4. STARTING AN ACTIVITY SYNTAX var activity = new MozActivity({ name: "/*Verb, usally 'pick', 'open', 'share' ...*/", data: { // We can pass parameters to the activity } }); ! activity.onsuccess = function() { // Success return from the activity // We can ask for the result, if any var result = this.result; console.log(result); }; ! activity.onerror = function() { // Called when a error happened console.log(this.error); };
  5. 5. WHERE CAN I FIND THEM? https://developer.mozilla.org/en-US/docs/WebAPI/Web_Activities
  6. 6. EXAMPLE HTTPS://GITHUB.COM/FIREFOXOS-LONDON-MEETUP/USING-WEB-ACTIVITIES
  7. 7. OFFERING OUR SERVICES • Is your app particularly good doing some task? • Do you want to drive more users to your app? • Make other developers to recognise your work!
  8. 8. DEFINING AN ACTIVITY 3 simple steps • Define it on your application manifest. • Handle the activity request. • Return the result of the activity.
  9. 9. DEFINE THE ACTIVITY IN YOUR MANIFEST FILE { // Your manifest goes here ! } // Activity registration, you can define as much // as you want "activities": { // It starts with the verb (pick, share, new .. "pick": { // Document to be opened "href": "./index.html", // How the activity will be opened "disposition": "inline", // Extra data to filter if we can handle // the activity request "filters": { "type": ["image/*","image/jpeg","image/png"] }, "returnValue": true } }
  10. 10. HANDLING THE ACTION navigator.mozSetMessageHandler('activity', function(activityRequest) { var options = activityRequest.source; ! // In options.name we have the verb used console.log(options.name); // options.data will contain the object // we used to invoke the activity console.log(options.data); ! });
  11. 11. RETURN THE RESULT navigator.mozSetMessageHandler('activity', function(activityRequest) { // Send back the result if (result) { activityRequest.postResult(result); } else { activityRequest.postError("Error executing the activity"); } });
  12. 12. EXAMPLE HTTPS://GITHUB.COM/FIREFOXOS-LONDON-MEETUP/ DEFINING-WEB-ACTIVITIES
  13. 13. THANKS!

×