SlideShare a Scribd company logo
1 of 66
Download to read offline
Pack It
                  Get your app ready for the App Store

Tuesday, September 25, 12
Agenda

                  Hybrid Apps

                  Introducing PhoneGap

                  Using Native APIs

                  Writing Custom PhoneGap Extensions




Tuesday, September 25, 12
Mobile Web Is Broken

                  No Push Notifications

                  No Filesystem Access

                  No Audio Recording

                  No Contacts




Tuesday, September 25, 12
Mobile Web Is Broken

                  No Push Notifications

                  No Filesystem Access

                  No Audio Recording

                  No Contacts




Tuesday, September 25, 12
Mobile Web Is Broken

                  No Push Notifications

                  No Filesystem Access

                  No Audio Recording

                  No Contacts




Tuesday, September 25, 12
Mobile Web Is Broken

                  No Push Notifications

                  No Filesystem Access

                  No Audio Recording

                  No Contacts




Tuesday, September 25, 12
Mobile Web Is Broken

                  No Push Notifications

                  No Filesystem Access

                  No Audio Recording

                  No Contacts




Tuesday, September 25, 12
Native Apps Are Broken

                  Rewrite same UI code
                  over and over again

                  Solve the same bugs

                  Maintainability
                  nightmare




Tuesday, September 25, 12
Hybrid Apps


                  A native app with an embedded web view

                  Runs mobile web code “in the box”

                  Runs native code “in the frame”




Tuesday, September 25, 12
Hybrid Apps



                            Mobile HTML




                            Native Wrapper


Tuesday, September 25, 12
Hybrid Apps +
                  Most of the app is written once in HTML/JS

                  Native parts are written in platform specific code
                  (Objective C, Java, etc.)

                  Works like a native app - can send to app store

                  Developer controls native code - can use native
                  APIs



Tuesday, September 25, 12
Hybrid Apps -

                  Complex Code

                  Requires many programming languages and data
                  transfer between them

                  Hard to debug




Tuesday, September 25, 12
Introducing PhoneGap

                  Open Source “connecting” solution from mobile
                  web to native

                  Exports native APIs to JS code using plugins

                  Also has an online beta build system




Tuesday, September 25, 12
Selected Apps


               Runners Ally   Taxi Madrid     Binary Clock    HAL 9000




                       Tank   Inside Trader     Radios       Roadtripper


Tuesday, September 25, 12
PhoneGap Demo



Tuesday, September 25, 12
PhoneGap Native Build


                  Install the SDK (Android or iPhone)

                  Install PhoneGap lib

                  Compile & Go




Tuesday, September 25, 12
Using The Build Server

                  Have a web app

                  prepare a config.xml file

                  Have an app icon image (png)

                  Register for the beta at:
                  https://build.phonegap.com/start




Tuesday, September 25, 12
Directory Structure
                  assets dir holds all the   assets/
                  files that are accessible     www/
                  from the html                  index.html
                                                 config.xml
                  It acts as the root of         icon.png
                  the web page                   css/
                                                 js/
                  Can use a komodo               img/
                  template



Tuesday, September 25, 12
Config.xml

                  An xml file with all metadata on your app

                  Used by PhoneGap’s build servers

                  Optional but highly recommended

                  Full spec: https://build.phonegap.com/docs/
                  config-xml




Tuesday, September 25, 12
Config.xml Elements
                                                                                      Widget xml root element
                  <?xml version="1.0" encoding="UTF-8"?>
                  <widget xmlns!   !    = "http://www.w3.org/ns/widgets"
                  !   xmlns:gap!   = "http://phonegap.com/ns/1.0"
                  !   id! !    = "com.phonegap.getting.started"
                  !   version ! "1.0.0">
                               =                                                      App Name & Description
                  !     <name>PhoneGap: Getting Started</name>

                  !    <description>
                  !    !    A template for getting started with PhoneGap development and build.phonegap.com
                  !    </description>
                       <icon src=”images/icon.png” />                                     App Icon
                  !     <gap:platforms>
                  !     !   <gap:platform   name="android" minVersion="2.1" />
                  !     !   <gap:platform   name="webos" />                         Platforms for the Build Server
                  !     !   <gap:platform   name="symbian.wrt" />
                  !     !   <gap:platform   name="blackberry" project="widgets"/>
                  !     </gap:platforms>

                  !     <icon src="icon.png" gap:role="default" />

                  !     <feature name="http://api.phonegap.com/1.0/geolocation"/>
                  !     <feature name="http://api.phonegap.com/1.0/network"/>
                                                                                     Features (for permissions)
                  !   <!-- sample preference specification -->
                  !   <!-- <preference name="autorotate" value="false" readonly="true"/> -->
                  </widget>




Tuesday, September 25, 12
Manual Build
                  Can also install locally as an addon to eclipse or
                  xcode

                  When used locally, no need for config.xml

                  Can integrate with private native code

                  Some features are still missing from build server

                  Requires native toolchain



Tuesday, September 25, 12
Installing Android SDK

                  Full SDK installation instructions:
                  http://developer.android.com/sdk/installing.html

                  When all is ready, start a new project and follow
                  PhoneGap step-by-step instructions at:
                  https://github.com/phonegap/phonegap/blob/
                  master/Android/README.md




Tuesday, September 25, 12
Q&A



Tuesday, September 25, 12
PhoneGap API

                  JavaScript interfaces to native device features

                  All required objects are inserted to the window by
                  phonegap.js

                  No need for native code




Tuesday, September 25, 12
PhoneGap’s APIs
                  Accelerometer   Events

                  Compass         Media

                  Device          Capture

                  Geolocation     Contacts

                  Storage         File

                  Camera          Notification

                  Connection



Tuesday, September 25, 12
PhoneGap’s APIs
                  Accelerometer   Events

                  Compass         Media

                  Device          Capture

                  Geolocation     Contacts

                  Storage         File

                  Camera          Notification

                  Connection



Tuesday, September 25, 12
Device Information

            var             name               =   device.name
            var             phonegap_version   =   device.phonegap
            var             os_name            =   device.platform
            var             os_version         =   device.version
            var             uuid               =   device.uuid



          Demo: examples/phonegap/DeviceInfo



Tuesday, September 25, 12
Notifications




Tuesday, September 25, 12
Notifications

            navigator.notification.alert(‘foo’);

            navigator.notification.confirm(‘are you
            sure ?’, yesCallback, [title], [labels]);

            navigator.notification.beep(times);
            navigator.notification.vibrate(ms);




Tuesday, September 25, 12
Notifications

                  iPhone ignores vibrate times

                  PhoneGap implements beeping on the iPhone by
                  playing an audio file. Developer must provide the
                  audio file named beep.wav and placed in the
                  www/ root folder




Tuesday, September 25, 12
Exercise


                  Use PhoneGap to write a native application that
                  shows current device details in a jQM style form

                  Add vibrate and beep buttons




Tuesday, September 25, 12
Contacts Access
                  An API for reading &
                  writing Contacts
                  information

                  contacts.create to add
                  a new contact

                  contact.find to fetch a
                  contact’s information



Tuesday, September 25, 12
Contact Methods
                                                     Preferred

         var contact = navigator.contacts.create( opts );

         // Example:

         var numbers = [];
         numbers[0] = new ContactField('mobile', '052-1121321', true);
         var friend = navigator.contact.create({
             'displayName' : 'Some User',
             'phoneNumbers' : numbers
         });




Tuesday, September 25, 12
Contact Methods

       function findAllContacts(success, error) {
           var fields = ['displayName'];
           navigator.contacts.find(fields, success, error);
       }




         An array of                 success               error
         field names                 callback             callback




Tuesday, September 25, 12
Contact Object
                  id                        ims (ContactField[])

                  displayName               organizations
                                            (ContactOrganizations[])
                  name (ContactName)
                                            birthday (Date)
                  nickname
                                            note (String)
                  phoneNumbers
                  (ContactField[])          photos (ContactField[])

                  emails (ContactField[])   categories (ContactField[])

                  addresses array           urls (ContactField[])



Tuesday, September 25, 12
Contact Methods
                  Contact.save()

                  Contact.remove()

                  Contact.clone()




Tuesday, September 25, 12
Address Book Example


                  Show full contact list

                  Exercise: write contact
                  info page




Tuesday, September 25, 12
Adding Contacts

                  Create a contact with contacts.create

                  Modify the contact’s properties

                  Save it to the device’s address book using
                  contact.save




Tuesday, September 25, 12
Q&A
                  Device

                  Notification

                  Contacts

                  Accelerometer

                  Events

                  Camera


Tuesday, September 25, 12
Accelerometer
             Mobile Movement Detection




Tuesday, September 25, 12
Accelerometer

                  Most mobile devices have accelerometers that
                  detect device motion

                  An accelerometer reports device position using
                  x,y,z coordinate vector

                  Need to register for accelerometer events




Tuesday, September 25, 12
Accelerometer


                  Register for Notifications

                  Handle accelerometer changes

                  Unregister when done




Tuesday, September 25, 12
Accelerometer API

                  watchAccelerometer(success, error, options)

                  clearWatch(watchId)

                  API Doc: http://docs.phonegap.com/
                  phonegap_accelerometer_accelerometer.md.html




Tuesday, September 25, 12
Demo
             examples/phonegap/
             Bouncers




Tuesday, September 25, 12
Accelerometer
                  Takeaways
                  accelerometer
                  measures acceleration.
                  That is measured in m/
                  s2

                  Imagine a ball inside
                  your phone. Now
                  measure that ball’s
                  acceleration when the
                  phone moves


Tuesday, September 25, 12
Exercise
                  Use accelerometer API to write a “shake” detector

                  App should display a red box in the center

                  When user shakes the phone, box changes color
                  to blue

                  Bonus: Have the box shade correspond to the
                  shaking power (stronger shake means darker
                  color)



Tuesday, September 25, 12
Q&A



Tuesday, September 25, 12
PhoneGap Events
                  PhoneGap triggers events when things happen on
                  the device

                  We already know the “deviceready” event

                  Handling events is performed using event listeners
                  in the DOM

                  Events are triggered on the document object



Tuesday, September 25, 12
PhoneGap Events

                  Write a handler function

                  Bind an Event Handler using:
                  document.addEventListener(‘eventname’, handler,
                  false);

                  Can also bind using jQuery




Tuesday, September 25, 12
PhoneGap Events
                  backbutton     online

                  deviceready    offline

                  menubutton

                  pause

                  resume

                  searchbutton



Tuesday, September 25, 12
BackButton Event

                  Android devices have a back button

                  Default behavior - go back one page. Tapping
                  back on the first page leaves the app

                  Implement event to override




Tuesday, September 25, 12
Menu Button
                  Menus are not enabled in phonegap by default

                  Users expect menu button to show them extra
                  options. This can now be performed

                  A footer with buttons or any other menu layout will
                  work here

                  Still cannot use platform menus



Tuesday, September 25, 12
Pause/Resume Events

                  Android & iOS platforms can send an app to the
                  background if something more important happens

                  No JS will run after a pause. This is your last
                  chance to save data or report back to server

                  App will resume on a ‘resume’ event




Tuesday, September 25, 12
online/offline events

                  When device gets connected to the internet,
                  phonegap sends an online event

                  When device gets disconnected, phonegap sends
                  an offline event

                  Use these to control behavior of network related
                  apps




Tuesday, September 25, 12
CAMERA API
    TAKE AND SHARE PHOTOS
Tuesday, September 25, 12
Camera API

                  Takes a picture using the device camera

                  Can also request for a saved image (from photo
                  gallery)

                  iPhone: use built in photo edit dialog for cropping




Tuesday, September 25, 12
Camera API

            options = {
               quality : 75,
               destinationType : Camera.DestinationType.DATA_URL,
               sourceType : Camera.PictureSourceType.CAMERA,
               allowEdit : true,
               encodingType : Camera.EncodingType.JPEG,
               targetWidth : 100,
               targetHeight : 100
            };

            navigator.camera.getPicture(success, error, options);




Tuesday, September 25, 12
Camera API
                  Quality is ranged 0..100

                  Destination type selects between DATA_URL and
                  FILE_URI

                  PictureSourceType selects between
                  PHOTOLIBRARY, CAMERA,
                  SAVEDPHOTOALBUM




Tuesday, September 25, 12
Use The Image - Data
                     function onSuccess(imageData) {

                            var img = document.querySelector(‘#img’);

                            img.src = “data:image/jpeg;base64,” + imageData
                     }




                     function onFail(msg) {

                            alert(‘fail because: ‘ + msg);

                     }




Tuesday, September 25, 12
Use The Image - File
                     function onSuccess(imageURI) {

                            var img = document.querySelector(‘#img’);

                            img.src = imageURI;
                     }




                     function onFail(msg) {

                            alert(‘fail because: ‘ + msg);

                     }




Tuesday, September 25, 12
Camera Tips

                  Use FILE_URI
                  destination type to
                  save on device
                  memory

                  Use DATA_URL to post
                  the data remotely




Tuesday, September 25, 12
Camera API - Missing

                  Check if device actually
                  has a camera (consider
                  iPod touch/iPads)

                  Use image overlay




Tuesday, September 25, 12
Exercise
                  Write a connection indicator app

                  App has a big circle in the middle

                  Circle color is red when offline, and green when online

                  Tapping the circle when it’s green takes a picture, and
                  use it as a background image.

                  Tapping the circle when it’s red takes a picture from
                  the gallery and use it as a background image



Tuesday, September 25, 12
PhoneGap Plugins

                  Each API we examined is just native code
                  “connected” to JS, and bridged by PhoneGap

                  Extending PhoneGap is easy by writing dedicated
                  plugins in native Java or Objective C code

                  A plugin can perform any native task




Tuesday, September 25, 12
Q&A



Tuesday, September 25, 12
Thank You


                  Ynon Perek

                  ynonperek@yahoo.com

                  ynonperek.com




Tuesday, September 25, 12

More Related Content

Similar to 07 PhoneGap

Cross-platform mobile that Works - Coobers
Cross-platform mobile that Works - CoobersCross-platform mobile that Works - Coobers
Cross-platform mobile that Works - CoobersCoobers
 
HTML5 for mobile development
HTML5 for mobile developmentHTML5 for mobile development
HTML5 for mobile developmentCarlos Justiniano
 
Getting Acquainted with PhoneGap
Getting Acquainted with PhoneGapGetting Acquainted with PhoneGap
Getting Acquainted with PhoneGapJoseph Labrecque
 
PhoneGap/PhoneGap Build - Amsterdam Adobe Camp
PhoneGap/PhoneGap Build - Amsterdam Adobe CampPhoneGap/PhoneGap Build - Amsterdam Adobe Camp
PhoneGap/PhoneGap Build - Amsterdam Adobe CampMihai Corlan
 
Xamarin Platform
Xamarin PlatformXamarin Platform
Xamarin PlatformLiddle Fang
 
Getting started with PhoneGap
Getting started with PhoneGapGetting started with PhoneGap
Getting started with PhoneGapMihai Corlan
 
Xamarin among Others - Vietnam Mobile Day 2017
Xamarin among Others - Vietnam Mobile Day 2017Xamarin among Others - Vietnam Mobile Day 2017
Xamarin among Others - Vietnam Mobile Day 2017Tuyến Vũ Đức
 
Building Cross-Platform JavaScript Apps using Cordova
Building Cross-Platform JavaScript Apps using CordovaBuilding Cross-Platform JavaScript Apps using Cordova
Building Cross-Platform JavaScript Apps using CordovaNoam Kfir
 
Тестирование мобильных приложений используя облачные сервисы. TestDroid, Test...
Тестирование мобильных приложений используя облачные сервисы. TestDroid, Test...Тестирование мобильных приложений используя облачные сервисы. TestDroid, Test...
Тестирование мобильных приложений используя облачные сервисы. TestDroid, Test...COMAQA.BY
 
Cross platform mobile app development tools review
Cross platform mobile app development tools reviewCross platform mobile app development tools review
Cross platform mobile app development tools reviewUday Kothari
 
Visual Studio 2017 Launch Event
Visual Studio 2017 Launch EventVisual Studio 2017 Launch Event
Visual Studio 2017 Launch EventJames Montemagno
 
App engine cloud_comp_expo_nyc
App engine cloud_comp_expo_nycApp engine cloud_comp_expo_nyc
App engine cloud_comp_expo_nycChris Schalk
 
stackconf 2022: Minimum Viable Security for Cloud Native Stacks
stackconf 2022: Minimum Viable Security for Cloud Native Stacksstackconf 2022: Minimum Viable Security for Cloud Native Stacks
stackconf 2022: Minimum Viable Security for Cloud Native StacksNETWAYS
 

Similar to 07 PhoneGap (20)

Cross-platform mobile that Works - Coobers
Cross-platform mobile that Works - CoobersCross-platform mobile that Works - Coobers
Cross-platform mobile that Works - Coobers
 
HTML5 for mobile development
HTML5 for mobile developmentHTML5 for mobile development
HTML5 for mobile development
 
Appium solution artizone
Appium solution   artizoneAppium solution   artizone
Appium solution artizone
 
Getting Acquainted with PhoneGap
Getting Acquainted with PhoneGapGetting Acquainted with PhoneGap
Getting Acquainted with PhoneGap
 
PhoneGap/PhoneGap Build - Amsterdam Adobe Camp
PhoneGap/PhoneGap Build - Amsterdam Adobe CampPhoneGap/PhoneGap Build - Amsterdam Adobe Camp
PhoneGap/PhoneGap Build - Amsterdam Adobe Camp
 
Xamarin Platform
Xamarin PlatformXamarin Platform
Xamarin Platform
 
Getting started with PhoneGap
Getting started with PhoneGapGetting started with PhoneGap
Getting started with PhoneGap
 
Xamarin among Others - Vietnam Mobile Day 2017
Xamarin among Others - Vietnam Mobile Day 2017Xamarin among Others - Vietnam Mobile Day 2017
Xamarin among Others - Vietnam Mobile Day 2017
 
Appium solution
Appium solutionAppium solution
Appium solution
 
Building Cross-Platform JavaScript Apps using Cordova
Building Cross-Platform JavaScript Apps using CordovaBuilding Cross-Platform JavaScript Apps using Cordova
Building Cross-Platform JavaScript Apps using Cordova
 
Тестирование мобильных приложений используя облачные сервисы. TestDroid, Test...
Тестирование мобильных приложений используя облачные сервисы. TestDroid, Test...Тестирование мобильных приложений используя облачные сервисы. TestDroid, Test...
Тестирование мобильных приложений используя облачные сервисы. TestDroid, Test...
 
Cross platform mobile app development tools review
Cross platform mobile app development tools reviewCross platform mobile app development tools review
Cross platform mobile app development tools review
 
C# rocks
C# rocksC# rocks
C# rocks
 
Phone gap
Phone gapPhone gap
Phone gap
 
Visual Studio 2017 Launch Event
Visual Studio 2017 Launch EventVisual Studio 2017 Launch Event
Visual Studio 2017 Launch Event
 
App engine cloud_comp_expo_nyc
App engine cloud_comp_expo_nycApp engine cloud_comp_expo_nyc
App engine cloud_comp_expo_nyc
 
Codename one
Codename oneCodename one
Codename one
 
stackconf 2022: Minimum Viable Security for Cloud Native Stacks
stackconf 2022: Minimum Viable Security for Cloud Native Stacksstackconf 2022: Minimum Viable Security for Cloud Native Stacks
stackconf 2022: Minimum Viable Security for Cloud Native Stacks
 
Mobile Apps Develpment - A Comparison
Mobile Apps Develpment - A ComparisonMobile Apps Develpment - A Comparison
Mobile Apps Develpment - A Comparison
 
Cross Platform Mobile Development
Cross Platform Mobile DevelopmentCross Platform Mobile Development
Cross Platform Mobile Development
 

More from Ynon Perek

09 performance
09 performance09 performance
09 performanceYnon Perek
 
Mobile Web Intro
Mobile Web IntroMobile Web Intro
Mobile Web IntroYnon Perek
 
Qt multi threads
Qt multi threadsQt multi threads
Qt multi threadsYnon Perek
 
Mobile Devices
Mobile DevicesMobile Devices
Mobile DevicesYnon Perek
 
Architecture app
Architecture appArchitecture app
Architecture appYnon Perek
 
Unit Testing JavaScript Applications
Unit Testing JavaScript ApplicationsUnit Testing JavaScript Applications
Unit Testing JavaScript ApplicationsYnon Perek
 
How to write easy-to-test JavaScript
How to write easy-to-test JavaScriptHow to write easy-to-test JavaScript
How to write easy-to-test JavaScriptYnon Perek
 
Introduction to Selenium and Ruby
Introduction to Selenium and RubyIntroduction to Selenium and Ruby
Introduction to Selenium and RubyYnon Perek
 
Introduction To Web Application Testing
Introduction To Web Application TestingIntroduction To Web Application Testing
Introduction To Web Application TestingYnon Perek
 
Qt Design Patterns
Qt Design PatternsQt Design Patterns
Qt Design PatternsYnon Perek
 
Web Application Security
Web Application SecurityWeb Application Security
Web Application SecurityYnon Perek
 
JavaScript DOM Manipulations
JavaScript DOM ManipulationsJavaScript DOM Manipulations
JavaScript DOM ManipulationsYnon Perek
 

More from Ynon Perek (20)

Regexp
RegexpRegexp
Regexp
 
Html5 intro
Html5 introHtml5 intro
Html5 intro
 
09 performance
09 performance09 performance
09 performance
 
Mobile Web Intro
Mobile Web IntroMobile Web Intro
Mobile Web Intro
 
Qt multi threads
Qt multi threadsQt multi threads
Qt multi threads
 
Vimperl
VimperlVimperl
Vimperl
 
Syllabus
SyllabusSyllabus
Syllabus
 
Mobile Devices
Mobile DevicesMobile Devices
Mobile Devices
 
Network
NetworkNetwork
Network
 
Architecture app
Architecture appArchitecture app
Architecture app
 
Cryptography
CryptographyCryptography
Cryptography
 
Unit Testing JavaScript Applications
Unit Testing JavaScript ApplicationsUnit Testing JavaScript Applications
Unit Testing JavaScript Applications
 
How to write easy-to-test JavaScript
How to write easy-to-test JavaScriptHow to write easy-to-test JavaScript
How to write easy-to-test JavaScript
 
Introduction to Selenium and Ruby
Introduction to Selenium and RubyIntroduction to Selenium and Ruby
Introduction to Selenium and Ruby
 
Introduction To Web Application Testing
Introduction To Web Application TestingIntroduction To Web Application Testing
Introduction To Web Application Testing
 
Accessibility
AccessibilityAccessibility
Accessibility
 
Js memory
Js memoryJs memory
Js memory
 
Qt Design Patterns
Qt Design PatternsQt Design Patterns
Qt Design Patterns
 
Web Application Security
Web Application SecurityWeb Application Security
Web Application Security
 
JavaScript DOM Manipulations
JavaScript DOM ManipulationsJavaScript DOM Manipulations
JavaScript DOM Manipulations
 

Recently uploaded

Google AI Hackathon: LLM based Evaluator for RAG
Google AI Hackathon: LLM based Evaluator for RAGGoogle AI Hackathon: LLM based Evaluator for RAG
Google AI Hackathon: LLM based Evaluator for RAGSujit Pal
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Paola De la Torre
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesSinan KOZAK
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024Results
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024The Digital Insurer
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersThousandEyes
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...shyamraj55
 
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | DelhiFULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhisoniya singh
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Servicegiselly40
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...HostedbyConfluent
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxOnBoard
 

Recently uploaded (20)

Google AI Hackathon: LLM based Evaluator for RAG
Google AI Hackathon: LLM based Evaluator for RAGGoogle AI Hackathon: LLM based Evaluator for RAG
Google AI Hackathon: LLM based Evaluator for RAG
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen Frames
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
 
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | DelhiFULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptx
 

07 PhoneGap

  • 1. Pack It Get your app ready for the App Store Tuesday, September 25, 12
  • 2. Agenda Hybrid Apps Introducing PhoneGap Using Native APIs Writing Custom PhoneGap Extensions Tuesday, September 25, 12
  • 3. Mobile Web Is Broken No Push Notifications No Filesystem Access No Audio Recording No Contacts Tuesday, September 25, 12
  • 4. Mobile Web Is Broken No Push Notifications No Filesystem Access No Audio Recording No Contacts Tuesday, September 25, 12
  • 5. Mobile Web Is Broken No Push Notifications No Filesystem Access No Audio Recording No Contacts Tuesday, September 25, 12
  • 6. Mobile Web Is Broken No Push Notifications No Filesystem Access No Audio Recording No Contacts Tuesday, September 25, 12
  • 7. Mobile Web Is Broken No Push Notifications No Filesystem Access No Audio Recording No Contacts Tuesday, September 25, 12
  • 8. Native Apps Are Broken Rewrite same UI code over and over again Solve the same bugs Maintainability nightmare Tuesday, September 25, 12
  • 9. Hybrid Apps A native app with an embedded web view Runs mobile web code “in the box” Runs native code “in the frame” Tuesday, September 25, 12
  • 10. Hybrid Apps Mobile HTML Native Wrapper Tuesday, September 25, 12
  • 11. Hybrid Apps + Most of the app is written once in HTML/JS Native parts are written in platform specific code (Objective C, Java, etc.) Works like a native app - can send to app store Developer controls native code - can use native APIs Tuesday, September 25, 12
  • 12. Hybrid Apps - Complex Code Requires many programming languages and data transfer between them Hard to debug Tuesday, September 25, 12
  • 13. Introducing PhoneGap Open Source “connecting” solution from mobile web to native Exports native APIs to JS code using plugins Also has an online beta build system Tuesday, September 25, 12
  • 14. Selected Apps Runners Ally Taxi Madrid Binary Clock HAL 9000 Tank Inside Trader Radios Roadtripper Tuesday, September 25, 12
  • 16. PhoneGap Native Build Install the SDK (Android or iPhone) Install PhoneGap lib Compile & Go Tuesday, September 25, 12
  • 17. Using The Build Server Have a web app prepare a config.xml file Have an app icon image (png) Register for the beta at: https://build.phonegap.com/start Tuesday, September 25, 12
  • 18. Directory Structure assets dir holds all the assets/ files that are accessible www/ from the html index.html config.xml It acts as the root of icon.png the web page css/ js/ Can use a komodo img/ template Tuesday, September 25, 12
  • 19. Config.xml An xml file with all metadata on your app Used by PhoneGap’s build servers Optional but highly recommended Full spec: https://build.phonegap.com/docs/ config-xml Tuesday, September 25, 12
  • 20. Config.xml Elements Widget xml root element <?xml version="1.0" encoding="UTF-8"?> <widget xmlns! ! = "http://www.w3.org/ns/widgets" ! xmlns:gap! = "http://phonegap.com/ns/1.0" ! id! ! = "com.phonegap.getting.started" ! version ! "1.0.0"> = App Name & Description ! <name>PhoneGap: Getting Started</name> ! <description> ! ! A template for getting started with PhoneGap development and build.phonegap.com ! </description> <icon src=”images/icon.png” /> App Icon ! <gap:platforms> ! ! <gap:platform name="android" minVersion="2.1" /> ! ! <gap:platform name="webos" /> Platforms for the Build Server ! ! <gap:platform name="symbian.wrt" /> ! ! <gap:platform name="blackberry" project="widgets"/> ! </gap:platforms> ! <icon src="icon.png" gap:role="default" /> ! <feature name="http://api.phonegap.com/1.0/geolocation"/> ! <feature name="http://api.phonegap.com/1.0/network"/> Features (for permissions) ! <!-- sample preference specification --> ! <!-- <preference name="autorotate" value="false" readonly="true"/> --> </widget> Tuesday, September 25, 12
  • 21. Manual Build Can also install locally as an addon to eclipse or xcode When used locally, no need for config.xml Can integrate with private native code Some features are still missing from build server Requires native toolchain Tuesday, September 25, 12
  • 22. Installing Android SDK Full SDK installation instructions: http://developer.android.com/sdk/installing.html When all is ready, start a new project and follow PhoneGap step-by-step instructions at: https://github.com/phonegap/phonegap/blob/ master/Android/README.md Tuesday, September 25, 12
  • 24. PhoneGap API JavaScript interfaces to native device features All required objects are inserted to the window by phonegap.js No need for native code Tuesday, September 25, 12
  • 25. PhoneGap’s APIs Accelerometer Events Compass Media Device Capture Geolocation Contacts Storage File Camera Notification Connection Tuesday, September 25, 12
  • 26. PhoneGap’s APIs Accelerometer Events Compass Media Device Capture Geolocation Contacts Storage File Camera Notification Connection Tuesday, September 25, 12
  • 27. Device Information var name = device.name var phonegap_version = device.phonegap var os_name = device.platform var os_version = device.version var uuid = device.uuid Demo: examples/phonegap/DeviceInfo Tuesday, September 25, 12
  • 29. Notifications navigator.notification.alert(‘foo’); navigator.notification.confirm(‘are you sure ?’, yesCallback, [title], [labels]); navigator.notification.beep(times); navigator.notification.vibrate(ms); Tuesday, September 25, 12
  • 30. Notifications iPhone ignores vibrate times PhoneGap implements beeping on the iPhone by playing an audio file. Developer must provide the audio file named beep.wav and placed in the www/ root folder Tuesday, September 25, 12
  • 31. Exercise Use PhoneGap to write a native application that shows current device details in a jQM style form Add vibrate and beep buttons Tuesday, September 25, 12
  • 32. Contacts Access An API for reading & writing Contacts information contacts.create to add a new contact contact.find to fetch a contact’s information Tuesday, September 25, 12
  • 33. Contact Methods Preferred var contact = navigator.contacts.create( opts ); // Example: var numbers = []; numbers[0] = new ContactField('mobile', '052-1121321', true); var friend = navigator.contact.create({ 'displayName' : 'Some User', 'phoneNumbers' : numbers }); Tuesday, September 25, 12
  • 34. Contact Methods function findAllContacts(success, error) { var fields = ['displayName']; navigator.contacts.find(fields, success, error); } An array of success error field names callback callback Tuesday, September 25, 12
  • 35. Contact Object id ims (ContactField[]) displayName organizations (ContactOrganizations[]) name (ContactName) birthday (Date) nickname note (String) phoneNumbers (ContactField[]) photos (ContactField[]) emails (ContactField[]) categories (ContactField[]) addresses array urls (ContactField[]) Tuesday, September 25, 12
  • 36. Contact Methods Contact.save() Contact.remove() Contact.clone() Tuesday, September 25, 12
  • 37. Address Book Example Show full contact list Exercise: write contact info page Tuesday, September 25, 12
  • 38. Adding Contacts Create a contact with contacts.create Modify the contact’s properties Save it to the device’s address book using contact.save Tuesday, September 25, 12
  • 39. Q&A Device Notification Contacts Accelerometer Events Camera Tuesday, September 25, 12
  • 40. Accelerometer Mobile Movement Detection Tuesday, September 25, 12
  • 41. Accelerometer Most mobile devices have accelerometers that detect device motion An accelerometer reports device position using x,y,z coordinate vector Need to register for accelerometer events Tuesday, September 25, 12
  • 42. Accelerometer Register for Notifications Handle accelerometer changes Unregister when done Tuesday, September 25, 12
  • 43. Accelerometer API watchAccelerometer(success, error, options) clearWatch(watchId) API Doc: http://docs.phonegap.com/ phonegap_accelerometer_accelerometer.md.html Tuesday, September 25, 12
  • 44. Demo examples/phonegap/ Bouncers Tuesday, September 25, 12
  • 45. Accelerometer Takeaways accelerometer measures acceleration. That is measured in m/ s2 Imagine a ball inside your phone. Now measure that ball’s acceleration when the phone moves Tuesday, September 25, 12
  • 46. Exercise Use accelerometer API to write a “shake” detector App should display a red box in the center When user shakes the phone, box changes color to blue Bonus: Have the box shade correspond to the shaking power (stronger shake means darker color) Tuesday, September 25, 12
  • 48. PhoneGap Events PhoneGap triggers events when things happen on the device We already know the “deviceready” event Handling events is performed using event listeners in the DOM Events are triggered on the document object Tuesday, September 25, 12
  • 49. PhoneGap Events Write a handler function Bind an Event Handler using: document.addEventListener(‘eventname’, handler, false); Can also bind using jQuery Tuesday, September 25, 12
  • 50. PhoneGap Events backbutton online deviceready offline menubutton pause resume searchbutton Tuesday, September 25, 12
  • 51. BackButton Event Android devices have a back button Default behavior - go back one page. Tapping back on the first page leaves the app Implement event to override Tuesday, September 25, 12
  • 52. Menu Button Menus are not enabled in phonegap by default Users expect menu button to show them extra options. This can now be performed A footer with buttons or any other menu layout will work here Still cannot use platform menus Tuesday, September 25, 12
  • 53. Pause/Resume Events Android & iOS platforms can send an app to the background if something more important happens No JS will run after a pause. This is your last chance to save data or report back to server App will resume on a ‘resume’ event Tuesday, September 25, 12
  • 54. online/offline events When device gets connected to the internet, phonegap sends an online event When device gets disconnected, phonegap sends an offline event Use these to control behavior of network related apps Tuesday, September 25, 12
  • 55. CAMERA API TAKE AND SHARE PHOTOS Tuesday, September 25, 12
  • 56. Camera API Takes a picture using the device camera Can also request for a saved image (from photo gallery) iPhone: use built in photo edit dialog for cropping Tuesday, September 25, 12
  • 57. Camera API options = { quality : 75, destinationType : Camera.DestinationType.DATA_URL, sourceType : Camera.PictureSourceType.CAMERA, allowEdit : true, encodingType : Camera.EncodingType.JPEG, targetWidth : 100, targetHeight : 100 }; navigator.camera.getPicture(success, error, options); Tuesday, September 25, 12
  • 58. Camera API Quality is ranged 0..100 Destination type selects between DATA_URL and FILE_URI PictureSourceType selects between PHOTOLIBRARY, CAMERA, SAVEDPHOTOALBUM Tuesday, September 25, 12
  • 59. Use The Image - Data function onSuccess(imageData) { var img = document.querySelector(‘#img’); img.src = “data:image/jpeg;base64,” + imageData } function onFail(msg) { alert(‘fail because: ‘ + msg); } Tuesday, September 25, 12
  • 60. Use The Image - File function onSuccess(imageURI) { var img = document.querySelector(‘#img’); img.src = imageURI; } function onFail(msg) { alert(‘fail because: ‘ + msg); } Tuesday, September 25, 12
  • 61. Camera Tips Use FILE_URI destination type to save on device memory Use DATA_URL to post the data remotely Tuesday, September 25, 12
  • 62. Camera API - Missing Check if device actually has a camera (consider iPod touch/iPads) Use image overlay Tuesday, September 25, 12
  • 63. Exercise Write a connection indicator app App has a big circle in the middle Circle color is red when offline, and green when online Tapping the circle when it’s green takes a picture, and use it as a background image. Tapping the circle when it’s red takes a picture from the gallery and use it as a background image Tuesday, September 25, 12
  • 64. PhoneGap Plugins Each API we examined is just native code “connected” to JS, and bridged by PhoneGap Extending PhoneGap is easy by writing dedicated plugins in native Java or Objective C code A plugin can perform any native task Tuesday, September 25, 12
  • 66. Thank You Ynon Perek ynonperek@yahoo.com ynonperek.com Tuesday, September 25, 12