Firefoxos London Meetup February 2014: Hands on Web Activities

14
FIREFOX OS LONDON MEETUP FEBRUARY 2014 Hands on Web Activities

description

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

Transcript of Firefoxos London Meetup February 2014: Hands on Web Activities

Page 1: Firefoxos London Meetup February 2014: Hands on Web Activities

FIREFOX OS LONDON MEETUP

FEBRUARY 2014!

Hands on Web Activities

Page 2: Firefoxos London Meetup February 2014: Hands on Web Activities

WELCOME!Today we are going to have a

practical session around !

Web Activities !

(and the new app manager!)

Page 3: Firefoxos London Meetup February 2014: Hands on Web Activities

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.

Page 4: Firefoxos London Meetup February 2014: Hands on Web Activities
Page 5: Firefoxos London Meetup February 2014: Hands on Web Activities

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); };

Page 6: Firefoxos London Meetup February 2014: Hands on Web Activities

WHERE CAN I FIND THEM?

https://developer.mozilla.org/en-US/docs/WebAPI/Web_Activities

Page 7: Firefoxos London Meetup February 2014: Hands on Web Activities

EXAMPLE HTTPS://GITHUB.COM/FIREFOXOS-LONDON-MEETUP/USING-WEB-ACTIVITIES

Page 8: Firefoxos London Meetup February 2014: Hands on Web Activities

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!

Page 9: Firefoxos London Meetup February 2014: Hands on Web Activities

DEFINING AN ACTIVITY

• Define it on your application manifest.

• Handle the activity request.

• Return the result of the activity.

3 simple steps

Page 10: Firefoxos London Meetup February 2014: Hands on Web Activities

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 } } }

Page 11: Firefoxos London Meetup February 2014: Hands on Web Activities

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); !});

Page 12: Firefoxos London Meetup February 2014: Hands on Web Activities

RETURN THE RESULT

navigator.mozSetMessageHandler('activity', function(activityRequest) { // Send back the result if (result) { activityRequest.postResult(result); } else { activityRequest.postError("Error executing the activity"); } });

Page 13: Firefoxos London Meetup February 2014: Hands on Web Activities

EXAMPLE HTTPS://GITHUB.COM/FIREFOXOS-LONDON-MEETUP/

DEFINING-WEB-ACTIVITIES

Page 14: Firefoxos London Meetup February 2014: Hands on Web Activities

THANKS!