SlideShare a Scribd company logo
1 of 26
Download to read offline
PhoneGap API Deep Dive

 Andrew Lunny, Nitobi, July 8 2010
PhoneGap Goal

  A set of consistent cross-platform APIs for
 accessing native device capabilities through
                  JavaScript

This is possible for a large subset of PhoneGap
                       APIs
However

• Some functionality is not present on all hardware
  o Accelerometer, Compass
• Some features aren't exposed by all platforms
  o SMS, Telephony, File System
• Some features are exposed in varying ways
  o Camera, Contacts
• Some features are platform specific
  o notification.activityStart, KeyEvent
PhoneGap 1.0
• Consistent Core API
• Plugins for majority of platform specific code
• Platform specific functionality for exceptional purposes


             Documentation Push
 • Reworking phonegap-docs
   o http://docs2.phonegap.com
   o http://github.com/phonegap/phonegap-docs/tree/
     rework
 • Better expose and fix inconsistencies

        When in doubt, check mobile-spec
API Outline
                                   D evic e
                                  N etwork
          B asic
                                Notific ation
                              D e bug C onsole

                              A c c elerometer
                                 C omp ass
        Sensors
                               G eoloc ation
                                Orientation

                                  C amera
                                 C onta cts
                                     File
User D ata / File Stora g e
                              Me dia (Audio)
                               Stora g e/Store
                              SMS/Tele phony
Basics

     Device, Network, Notification, Debug

o   Fundamentals for mobile apps and development
o   Well-supported on all platforms
o   Consistent core, with platform specific extensions
Device
   iPhone, Android, BlackBerry, Palm, Symbian.wrt

      A JS Object with String/Boolean fields

Everywhere:    navigator.device.uuid
               navigator.device.platform

except Palm:   navigator.device.name
               navigator.device.version


except Palm  navigator.device.gap ||
and Symbian: navigator.device.gapVersion
                    device.gap = iPhone and BlackBerry
                    device.gapVersion = Android
Network
 iPhone, Android, BlackBerry, Palm, Symbian.wrt

One common public function: isReachable


BlackBerry also has Network.XHR
since the BlackBerry webview doesn't give us an
XMLHttpRequest by default

Android 2.2: ononline and onoffline events
navigator.network.isReachable(hostname,
   callback, options);

The callback function is called with the parameter foo,
which is used to compare the NetworkStatus against
the NetworkStatus constants (for example,
NetworkStatus.NOT_REACHABLE)

Palm/Symbian (what we want going forward)
foo != NetworkStatus.NOT_REACHABLE

iPhone
foo.remoteHostStatus !=
NetworkStatus.NOT_REACHABLE

Android/BlackBerry
foo.code != NetworkStatus.NOT_REACHABLE
Notification
       iPhone, Android, BlackBerry, Palm, Symbian.wrt


   Common      navigator.notification.alert

Not on Symbian navigator.notification.beep

Not on Palm    navigator.notification.vibrate

BlackBerry only navigator.notification.blink

 iPhone only    confirm
                activityStart, activityStop
                loadingStart, loadingStop
DebugConsole
iPhone, Android, BlackBerry, Palm, Symbian.wrt


       debug.log(msg)
       debug.warn(msg)
       debug.error(msg)

Android currently uses console.log

Both Android and BlackBerry should and will
implement these
Sensors

             Accelerometer, Compass,
            Geolocation, Orientation

o   All related to physical state of device
o   Time sensitive and liable to change
o   Consistent between platforms and consistent
    between environment modules
o   Moving into the browser
    • Google I/O Keynote promises all of these in
      Browser soon:
    • http://bit.ly/android-io
    • cf. http://dev.w3.org/geo/api/spec-source-
      orientation.html
Sensor APIs

navigator.sensor.getCurrentVariable(success,
error, options);
• asynchronously calls success with the current reading/status

navigator.sensor.watchVariable(success, error,
options);
• calls getCurrentVariable repeatedly, at frequency
  specified in options parameter; returns a watch id

navigator.sensor.clearWatch(watchId);
• cancels the watch set by watchVariable
Accelerometer
      iPhone, Android, BlackBerry, Palm, Symbian.wrt

navigator.accelerometer.getCurrentAcceleration
navigator.accelerometer.watchAcceleration
navigator.accelerometer.clearWatch


    Not supported on BlackBerry because the hardware
    has limited support (depending on the handset)
Compass
    iPhone, Android, BlackBerry, Palm, Symbian.wrt

navigator.compass.getCurrentHeading
navigator.compass.watchHeading
navigator.compass.clearWatch


   Palm and Symbian: no hardware support

   BlackBerry: depends on the device, not implemented
   yet
Geolocation
    iPhone, Android, BlackBerry, Palm, Symbian.wrt

navigator.geolocation.getCurrentPosition
navigator.geolocation.watchPosition
navigator.geolocation.clearWatch


   Where available (iPhone, Android 2.0+), PhoneGap
   uses the browser's geolocation API, rather than
   implementing our own
Orientation
    iPhone, Android, BlackBerry, Palm, Symbian.wrt
navigator.orientation.getCurrentOrientation
navigator.orientation.watchOrientation
navigator.orientation.clearWatch

   Unlikely for BlackBerry (only makes sense on
   certain handsets)

   Android: probably wait for Browser implementation

   iPhone fires orientationChange event
   automagically; you can use window.orientation
   instead of the PhoneGap method

   CSS3 media queries can also be used
User Data / File Storage

Camera, Contacts, File, Media (Audio),
     Storage/Store, SMS/Telephony

o   Reading and writing what's normally inaccessible
o   Most prone to inconsistency
    • between platforms
    • between device models/OS versions
o   Least settled PhoneGap APIs
Camera
    iPhone, Android, BlackBerry, Palm, Symbian.wrt

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

   Android, iPhone   success is passed a base-64 string
                     of image data

   BlackBerry, Palm success is passed a file path to the
                    image
   Symbian.wrt       success is passed an array of file
                     paths
Contacts
     iPhone, Android, BlackBerry, Palm, Symbian.wrt

Android, Blackberry,   navigator.contacts.find
Symbian                (filter, success, error,
                       options);

                       filter is an object of type
                       Contact

iPhone                 getAllContacts
                       newContact
                       chooseContact
                       displayContact
                       removeContact
                       contactsCount
Contacts

o   The most inconsistent between platforms
o   Test on devices, not just simulators!
File
 iPhone, Android, BlackBerry, Palm, Symbian.wrt

   navigator.fileMgr
   FileReader object
   FileWriter object

Palm webOS does not allow File I/O
  File.read is implemented with an XHR
BlackBerry should be implemented...
• use Store (see later slide) instead

Android & iPhone: based loosely on W3C file spec:
http://bit.ly/w3cfile
example API usage: http://bit.ly/pg-file
Media (Audio)
   iPhone, Android, BlackBerry, Palm, Symbian.wrt
var mySong = new Media
("urthebest.mp3",success,error);
mySong.play();
mySong.pause();
mySong.stop();
  Blackberry, Palm and Symbian as Audio, not
  Media

  iPhone and Android can record audio also
   • iPhone: startAudioRecord,
     stopAudioRecord
   • Android: startRecord,
     stopRecordingAudio
Storage/Store
  iPhone, Android, BlackBerry, Palm, Symbian.wrt
iPhone/Android 2.0+/Palm: unneeded - use
localStorage or HTML5 db

Android < 2.0: sets up an SQLite database,
accessed through window.openDatabase
  • Unstable: use with caution

Symbian: key/value store:
navigator.storage.getItem
navigator.storage.setItem

BlackBerry: key/value store:
navigator.store.get
navigator.store.put
SMS/Telephony
    iPhone, Android, BlackBerry, Palm, Symbian.wrt

navigator.sms.send(number, message, success,
error, options);
navigator.telephony.send(number);

   To be implemented on iPhone/Android

   Any platform: set link HREF to sms: or tel:

   In all cases, the user must confirm before the call or
   message is placed
Questions or Feedback
 @alunny, andrew.lunny@nitobi.com

More Related Content

Similar to Phonegap deep-dive

Open Source to the Rescue of Mobile App and Mobile Web Fragmentation
Open Source to the Rescue of Mobile App and Mobile Web FragmentationOpen Source to the Rescue of Mobile App and Mobile Web Fragmentation
Open Source to the Rescue of Mobile App and Mobile Web FragmentationTom Deryckere
 
Mobile testingartifacts
Mobile testingartifactsMobile testingartifacts
Mobile testingartifactsPragya Rastogi
 
HTML5 로 iPhone App 만들기
HTML5 로 iPhone App 만들기HTML5 로 iPhone App 만들기
HTML5 로 iPhone App 만들기JungHyuk Kwon
 
MOET: Mobile End-to-End Testing
MOET: Mobile End-to-End TestingMOET: Mobile End-to-End Testing
MOET: Mobile End-to-End Testingmobiletestsummit
 
Hybrid application development
Hybrid application developmentHybrid application development
Hybrid application developmentEngin Hatay
 
Preparing your QA team for mobile testing
Preparing your QA team for mobile testingPreparing your QA team for mobile testing
Preparing your QA team for mobile testingGeoffrey Goetz
 
Addressing Mobile App Testing Challenges
Addressing Mobile App Testing ChallengesAddressing Mobile App Testing Challenges
Addressing Mobile App Testing ChallengesLee Barnes
 
Health Care Clipboard iPad Application
Health Care Clipboard iPad ApplicationHealth Care Clipboard iPad Application
Health Care Clipboard iPad ApplicationJose Ortega
 
Mobile Bootcamp Presentation: Mobile Application Development Platforms
Mobile Bootcamp Presentation: Mobile Application Development PlatformsMobile Bootcamp Presentation: Mobile Application Development Platforms
Mobile Bootcamp Presentation: Mobile Application Development PlatformsWilfred Mutua Mworia
 
Programing for the iPhone
Programing for the iPhonePrograming for the iPhone
Programing for the iPhoneMike Qaissaunee
 
Introduction to Mobile applications testing (english)
Introduction to Mobile applications testing (english)Introduction to Mobile applications testing (english)
Introduction to Mobile applications testing (english)Oleg Nikiforov
 
Contextual Voice/Communications as an App or App Feature (on Android)
Contextual Voice/Communications as an App or App Feature (on Android)Contextual Voice/Communications as an App or App Feature (on Android)
Contextual Voice/Communications as an App or App Feature (on Android)Carlos Enrique Ortiz
 
Fixing the mobile web - Internet World Romania
Fixing the mobile web - Internet World RomaniaFixing the mobile web - Internet World Romania
Fixing the mobile web - Internet World RomaniaChristian Heilmann
 
Philly ete-2011
Philly ete-2011Philly ete-2011
Philly ete-2011davyjones
 
Device APIs at TakeOff Conference
Device APIs at TakeOff ConferenceDevice APIs at TakeOff Conference
Device APIs at TakeOff Conferencedianacheng
 
Intro to PhoneGap and PhoneGap Build
Intro to PhoneGap and PhoneGap BuildIntro to PhoneGap and PhoneGap Build
Intro to PhoneGap and PhoneGap BuildChris Griffith
 
An end-to-end experience of Windows Phone 7 development (Part 1)
An end-to-end experience of Windows Phone 7 development (Part 1)An end-to-end experience of Windows Phone 7 development (Part 1)
An end-to-end experience of Windows Phone 7 development (Part 1)rudigrobler
 

Similar to Phonegap deep-dive (20)

Open Source to the Rescue of Mobile App and Mobile Web Fragmentation
Open Source to the Rescue of Mobile App and Mobile Web FragmentationOpen Source to the Rescue of Mobile App and Mobile Web Fragmentation
Open Source to the Rescue of Mobile App and Mobile Web Fragmentation
 
Mobile testingartifacts
Mobile testingartifactsMobile testingartifacts
Mobile testingartifacts
 
HTML5 로 iPhone App 만들기
HTML5 로 iPhone App 만들기HTML5 로 iPhone App 만들기
HTML5 로 iPhone App 만들기
 
MOET: Mobile End-to-End Testing
MOET: Mobile End-to-End TestingMOET: Mobile End-to-End Testing
MOET: Mobile End-to-End Testing
 
Hybrid application development
Hybrid application developmentHybrid application development
Hybrid application development
 
Preparing your QA team for mobile testing
Preparing your QA team for mobile testingPreparing your QA team for mobile testing
Preparing your QA team for mobile testing
 
Addressing Mobile App Testing Challenges
Addressing Mobile App Testing ChallengesAddressing Mobile App Testing Challenges
Addressing Mobile App Testing Challenges
 
Health Care Clipboard iPad Application
Health Care Clipboard iPad ApplicationHealth Care Clipboard iPad Application
Health Care Clipboard iPad Application
 
Mobile Bootcamp Presentation: Mobile Application Development Platforms
Mobile Bootcamp Presentation: Mobile Application Development PlatformsMobile Bootcamp Presentation: Mobile Application Development Platforms
Mobile Bootcamp Presentation: Mobile Application Development Platforms
 
Programing for the iPhone
Programing for the iPhonePrograming for the iPhone
Programing for the iPhone
 
Iphone
IphoneIphone
Iphone
 
Introduction to Mobile applications testing (english)
Introduction to Mobile applications testing (english)Introduction to Mobile applications testing (english)
Introduction to Mobile applications testing (english)
 
Contextual Voice/Communications as an App or App Feature (on Android)
Contextual Voice/Communications as an App or App Feature (on Android)Contextual Voice/Communications as an App or App Feature (on Android)
Contextual Voice/Communications as an App or App Feature (on Android)
 
Mobile Application Testing
Mobile Application TestingMobile Application Testing
Mobile Application Testing
 
Fixing the mobile web - Internet World Romania
Fixing the mobile web - Internet World RomaniaFixing the mobile web - Internet World Romania
Fixing the mobile web - Internet World Romania
 
Philly ete-2011
Philly ete-2011Philly ete-2011
Philly ete-2011
 
Device APIs at TakeOff Conference
Device APIs at TakeOff ConferenceDevice APIs at TakeOff Conference
Device APIs at TakeOff Conference
 
phonegap_101
phonegap_101phonegap_101
phonegap_101
 
Intro to PhoneGap and PhoneGap Build
Intro to PhoneGap and PhoneGap BuildIntro to PhoneGap and PhoneGap Build
Intro to PhoneGap and PhoneGap Build
 
An end-to-end experience of Windows Phone 7 development (Part 1)
An end-to-end experience of Windows Phone 7 development (Part 1)An end-to-end experience of Windows Phone 7 development (Part 1)
An end-to-end experience of Windows Phone 7 development (Part 1)
 

Recently uploaded

Intro to Passkeys and the State of Passwordless.pptx
Intro to Passkeys and the State of Passwordless.pptxIntro to Passkeys and the State of Passwordless.pptx
Intro to Passkeys and the State of Passwordless.pptxFIDO Alliance
 
How we scaled to 80K users by doing nothing!.pdf
How we scaled to 80K users by doing nothing!.pdfHow we scaled to 80K users by doing nothing!.pdf
How we scaled to 80K users by doing nothing!.pdfSrushith Repakula
 
Design and Development of a Provenance Capture Platform for Data Science
Design and Development of a Provenance Capture Platform for Data ScienceDesign and Development of a Provenance Capture Platform for Data Science
Design and Development of a Provenance Capture Platform for Data SciencePaolo Missier
 
Tales from a Passkey Provider Progress from Awareness to Implementation.pptx
Tales from a Passkey Provider  Progress from Awareness to Implementation.pptxTales from a Passkey Provider  Progress from Awareness to Implementation.pptx
Tales from a Passkey Provider Progress from Awareness to Implementation.pptxFIDO Alliance
 
Easier, Faster, and More Powerful – Alles Neu macht der Mai -Wir durchleuchte...
Easier, Faster, and More Powerful – Alles Neu macht der Mai -Wir durchleuchte...Easier, Faster, and More Powerful – Alles Neu macht der Mai -Wir durchleuchte...
Easier, Faster, and More Powerful – Alles Neu macht der Mai -Wir durchleuchte...panagenda
 
Using IESVE for Room Loads Analysis - UK & Ireland
Using IESVE for Room Loads Analysis - UK & IrelandUsing IESVE for Room Loads Analysis - UK & Ireland
Using IESVE for Room Loads Analysis - UK & IrelandIES VE
 
ADP Passwordless Journey Case Study.pptx
ADP Passwordless Journey Case Study.pptxADP Passwordless Journey Case Study.pptx
ADP Passwordless Journey Case Study.pptxFIDO Alliance
 
(Explainable) Data-Centric AI: what are you explaininhg, and to whom?
(Explainable) Data-Centric AI: what are you explaininhg, and to whom?(Explainable) Data-Centric AI: what are you explaininhg, and to whom?
(Explainable) Data-Centric AI: what are you explaininhg, and to whom?Paolo Missier
 
Design Guidelines for Passkeys 2024.pptx
Design Guidelines for Passkeys 2024.pptxDesign Guidelines for Passkeys 2024.pptx
Design Guidelines for Passkeys 2024.pptxFIDO Alliance
 
Top 10 CodeIgniter Development Companies
Top 10 CodeIgniter Development CompaniesTop 10 CodeIgniter Development Companies
Top 10 CodeIgniter Development CompaniesTopCSSGallery
 
TopCryptoSupers 12thReport OrionX May2024
TopCryptoSupers 12thReport OrionX May2024TopCryptoSupers 12thReport OrionX May2024
TopCryptoSupers 12thReport OrionX May2024Stephen Perrenod
 
Event-Driven Architecture Masterclass: Integrating Distributed Data Stores Ac...
Event-Driven Architecture Masterclass: Integrating Distributed Data Stores Ac...Event-Driven Architecture Masterclass: Integrating Distributed Data Stores Ac...
Event-Driven Architecture Masterclass: Integrating Distributed Data Stores Ac...ScyllaDB
 
Extensible Python: Robustness through Addition - PyCon 2024
Extensible Python: Robustness through Addition - PyCon 2024Extensible Python: Robustness through Addition - PyCon 2024
Extensible Python: Robustness through Addition - PyCon 2024Patrick Viafore
 
Continuing Bonds Through AI: A Hermeneutic Reflection on Thanabots
Continuing Bonds Through AI: A Hermeneutic Reflection on ThanabotsContinuing Bonds Through AI: A Hermeneutic Reflection on Thanabots
Continuing Bonds Through AI: A Hermeneutic Reflection on ThanabotsLeah Henrickson
 
UiPath manufacturing technology benefits and AI overview
UiPath manufacturing technology benefits and AI overviewUiPath manufacturing technology benefits and AI overview
UiPath manufacturing technology benefits and AI overviewDianaGray10
 
Frisco Automating Purchase Orders with MuleSoft IDP- May 10th, 2024.pptx.pdf
Frisco Automating Purchase Orders with MuleSoft IDP- May 10th, 2024.pptx.pdfFrisco Automating Purchase Orders with MuleSoft IDP- May 10th, 2024.pptx.pdf
Frisco Automating Purchase Orders with MuleSoft IDP- May 10th, 2024.pptx.pdfAnubhavMangla3
 
Event-Driven Architecture Masterclass: Engineering a Robust, High-performance...
Event-Driven Architecture Masterclass: Engineering a Robust, High-performance...Event-Driven Architecture Masterclass: Engineering a Robust, High-performance...
Event-Driven Architecture Masterclass: Engineering a Robust, High-performance...ScyllaDB
 
Event-Driven Architecture Masterclass: Challenges in Stream Processing
Event-Driven Architecture Masterclass: Challenges in Stream ProcessingEvent-Driven Architecture Masterclass: Challenges in Stream Processing
Event-Driven Architecture Masterclass: Challenges in Stream ProcessingScyllaDB
 
The Zero-ETL Approach: Enhancing Data Agility and Insight
The Zero-ETL Approach: Enhancing Data Agility and InsightThe Zero-ETL Approach: Enhancing Data Agility and Insight
The Zero-ETL Approach: Enhancing Data Agility and InsightSafe Software
 
WebRTC and SIP not just audio and video @ OpenSIPS 2024
WebRTC and SIP not just audio and video @ OpenSIPS 2024WebRTC and SIP not just audio and video @ OpenSIPS 2024
WebRTC and SIP not just audio and video @ OpenSIPS 2024Lorenzo Miniero
 

Recently uploaded (20)

Intro to Passkeys and the State of Passwordless.pptx
Intro to Passkeys and the State of Passwordless.pptxIntro to Passkeys and the State of Passwordless.pptx
Intro to Passkeys and the State of Passwordless.pptx
 
How we scaled to 80K users by doing nothing!.pdf
How we scaled to 80K users by doing nothing!.pdfHow we scaled to 80K users by doing nothing!.pdf
How we scaled to 80K users by doing nothing!.pdf
 
Design and Development of a Provenance Capture Platform for Data Science
Design and Development of a Provenance Capture Platform for Data ScienceDesign and Development of a Provenance Capture Platform for Data Science
Design and Development of a Provenance Capture Platform for Data Science
 
Tales from a Passkey Provider Progress from Awareness to Implementation.pptx
Tales from a Passkey Provider  Progress from Awareness to Implementation.pptxTales from a Passkey Provider  Progress from Awareness to Implementation.pptx
Tales from a Passkey Provider Progress from Awareness to Implementation.pptx
 
Easier, Faster, and More Powerful – Alles Neu macht der Mai -Wir durchleuchte...
Easier, Faster, and More Powerful – Alles Neu macht der Mai -Wir durchleuchte...Easier, Faster, and More Powerful – Alles Neu macht der Mai -Wir durchleuchte...
Easier, Faster, and More Powerful – Alles Neu macht der Mai -Wir durchleuchte...
 
Using IESVE for Room Loads Analysis - UK & Ireland
Using IESVE for Room Loads Analysis - UK & IrelandUsing IESVE for Room Loads Analysis - UK & Ireland
Using IESVE for Room Loads Analysis - UK & Ireland
 
ADP Passwordless Journey Case Study.pptx
ADP Passwordless Journey Case Study.pptxADP Passwordless Journey Case Study.pptx
ADP Passwordless Journey Case Study.pptx
 
(Explainable) Data-Centric AI: what are you explaininhg, and to whom?
(Explainable) Data-Centric AI: what are you explaininhg, and to whom?(Explainable) Data-Centric AI: what are you explaininhg, and to whom?
(Explainable) Data-Centric AI: what are you explaininhg, and to whom?
 
Design Guidelines for Passkeys 2024.pptx
Design Guidelines for Passkeys 2024.pptxDesign Guidelines for Passkeys 2024.pptx
Design Guidelines for Passkeys 2024.pptx
 
Top 10 CodeIgniter Development Companies
Top 10 CodeIgniter Development CompaniesTop 10 CodeIgniter Development Companies
Top 10 CodeIgniter Development Companies
 
TopCryptoSupers 12thReport OrionX May2024
TopCryptoSupers 12thReport OrionX May2024TopCryptoSupers 12thReport OrionX May2024
TopCryptoSupers 12thReport OrionX May2024
 
Event-Driven Architecture Masterclass: Integrating Distributed Data Stores Ac...
Event-Driven Architecture Masterclass: Integrating Distributed Data Stores Ac...Event-Driven Architecture Masterclass: Integrating Distributed Data Stores Ac...
Event-Driven Architecture Masterclass: Integrating Distributed Data Stores Ac...
 
Extensible Python: Robustness through Addition - PyCon 2024
Extensible Python: Robustness through Addition - PyCon 2024Extensible Python: Robustness through Addition - PyCon 2024
Extensible Python: Robustness through Addition - PyCon 2024
 
Continuing Bonds Through AI: A Hermeneutic Reflection on Thanabots
Continuing Bonds Through AI: A Hermeneutic Reflection on ThanabotsContinuing Bonds Through AI: A Hermeneutic Reflection on Thanabots
Continuing Bonds Through AI: A Hermeneutic Reflection on Thanabots
 
UiPath manufacturing technology benefits and AI overview
UiPath manufacturing technology benefits and AI overviewUiPath manufacturing technology benefits and AI overview
UiPath manufacturing technology benefits and AI overview
 
Frisco Automating Purchase Orders with MuleSoft IDP- May 10th, 2024.pptx.pdf
Frisco Automating Purchase Orders with MuleSoft IDP- May 10th, 2024.pptx.pdfFrisco Automating Purchase Orders with MuleSoft IDP- May 10th, 2024.pptx.pdf
Frisco Automating Purchase Orders with MuleSoft IDP- May 10th, 2024.pptx.pdf
 
Event-Driven Architecture Masterclass: Engineering a Robust, High-performance...
Event-Driven Architecture Masterclass: Engineering a Robust, High-performance...Event-Driven Architecture Masterclass: Engineering a Robust, High-performance...
Event-Driven Architecture Masterclass: Engineering a Robust, High-performance...
 
Event-Driven Architecture Masterclass: Challenges in Stream Processing
Event-Driven Architecture Masterclass: Challenges in Stream ProcessingEvent-Driven Architecture Masterclass: Challenges in Stream Processing
Event-Driven Architecture Masterclass: Challenges in Stream Processing
 
The Zero-ETL Approach: Enhancing Data Agility and Insight
The Zero-ETL Approach: Enhancing Data Agility and InsightThe Zero-ETL Approach: Enhancing Data Agility and Insight
The Zero-ETL Approach: Enhancing Data Agility and Insight
 
WebRTC and SIP not just audio and video @ OpenSIPS 2024
WebRTC and SIP not just audio and video @ OpenSIPS 2024WebRTC and SIP not just audio and video @ OpenSIPS 2024
WebRTC and SIP not just audio and video @ OpenSIPS 2024
 

Phonegap deep-dive

  • 1. PhoneGap API Deep Dive Andrew Lunny, Nitobi, July 8 2010
  • 2. PhoneGap Goal A set of consistent cross-platform APIs for accessing native device capabilities through JavaScript This is possible for a large subset of PhoneGap APIs
  • 3. However • Some functionality is not present on all hardware o Accelerometer, Compass • Some features aren't exposed by all platforms o SMS, Telephony, File System • Some features are exposed in varying ways o Camera, Contacts • Some features are platform specific o notification.activityStart, KeyEvent
  • 4. PhoneGap 1.0 • Consistent Core API • Plugins for majority of platform specific code • Platform specific functionality for exceptional purposes Documentation Push • Reworking phonegap-docs o http://docs2.phonegap.com o http://github.com/phonegap/phonegap-docs/tree/ rework • Better expose and fix inconsistencies When in doubt, check mobile-spec
  • 5. API Outline D evic e N etwork B asic Notific ation D e bug C onsole A c c elerometer C omp ass Sensors G eoloc ation Orientation C amera C onta cts File User D ata / File Stora g e Me dia (Audio) Stora g e/Store SMS/Tele phony
  • 6. Basics Device, Network, Notification, Debug o Fundamentals for mobile apps and development o Well-supported on all platforms o Consistent core, with platform specific extensions
  • 7. Device iPhone, Android, BlackBerry, Palm, Symbian.wrt A JS Object with String/Boolean fields Everywhere: navigator.device.uuid navigator.device.platform except Palm: navigator.device.name navigator.device.version except Palm navigator.device.gap || and Symbian: navigator.device.gapVersion device.gap = iPhone and BlackBerry device.gapVersion = Android
  • 8. Network iPhone, Android, BlackBerry, Palm, Symbian.wrt One common public function: isReachable BlackBerry also has Network.XHR since the BlackBerry webview doesn't give us an XMLHttpRequest by default Android 2.2: ononline and onoffline events
  • 9. navigator.network.isReachable(hostname, callback, options); The callback function is called with the parameter foo, which is used to compare the NetworkStatus against the NetworkStatus constants (for example, NetworkStatus.NOT_REACHABLE) Palm/Symbian (what we want going forward) foo != NetworkStatus.NOT_REACHABLE iPhone foo.remoteHostStatus != NetworkStatus.NOT_REACHABLE Android/BlackBerry foo.code != NetworkStatus.NOT_REACHABLE
  • 10. Notification iPhone, Android, BlackBerry, Palm, Symbian.wrt Common navigator.notification.alert Not on Symbian navigator.notification.beep Not on Palm navigator.notification.vibrate BlackBerry only navigator.notification.blink iPhone only confirm activityStart, activityStop loadingStart, loadingStop
  • 11. DebugConsole iPhone, Android, BlackBerry, Palm, Symbian.wrt debug.log(msg) debug.warn(msg) debug.error(msg) Android currently uses console.log Both Android and BlackBerry should and will implement these
  • 12. Sensors Accelerometer, Compass, Geolocation, Orientation o All related to physical state of device o Time sensitive and liable to change o Consistent between platforms and consistent between environment modules o Moving into the browser • Google I/O Keynote promises all of these in Browser soon: • http://bit.ly/android-io • cf. http://dev.w3.org/geo/api/spec-source- orientation.html
  • 13. Sensor APIs navigator.sensor.getCurrentVariable(success, error, options); • asynchronously calls success with the current reading/status navigator.sensor.watchVariable(success, error, options); • calls getCurrentVariable repeatedly, at frequency specified in options parameter; returns a watch id navigator.sensor.clearWatch(watchId); • cancels the watch set by watchVariable
  • 14. Accelerometer iPhone, Android, BlackBerry, Palm, Symbian.wrt navigator.accelerometer.getCurrentAcceleration navigator.accelerometer.watchAcceleration navigator.accelerometer.clearWatch Not supported on BlackBerry because the hardware has limited support (depending on the handset)
  • 15. Compass iPhone, Android, BlackBerry, Palm, Symbian.wrt navigator.compass.getCurrentHeading navigator.compass.watchHeading navigator.compass.clearWatch Palm and Symbian: no hardware support BlackBerry: depends on the device, not implemented yet
  • 16. Geolocation iPhone, Android, BlackBerry, Palm, Symbian.wrt navigator.geolocation.getCurrentPosition navigator.geolocation.watchPosition navigator.geolocation.clearWatch Where available (iPhone, Android 2.0+), PhoneGap uses the browser's geolocation API, rather than implementing our own
  • 17. Orientation iPhone, Android, BlackBerry, Palm, Symbian.wrt navigator.orientation.getCurrentOrientation navigator.orientation.watchOrientation navigator.orientation.clearWatch Unlikely for BlackBerry (only makes sense on certain handsets) Android: probably wait for Browser implementation iPhone fires orientationChange event automagically; you can use window.orientation instead of the PhoneGap method CSS3 media queries can also be used
  • 18. User Data / File Storage Camera, Contacts, File, Media (Audio), Storage/Store, SMS/Telephony o Reading and writing what's normally inaccessible o Most prone to inconsistency • between platforms • between device models/OS versions o Least settled PhoneGap APIs
  • 19. Camera iPhone, Android, BlackBerry, Palm, Symbian.wrt navigator.camera.getPicture(success, error, options); Android, iPhone success is passed a base-64 string of image data BlackBerry, Palm success is passed a file path to the image Symbian.wrt success is passed an array of file paths
  • 20. Contacts iPhone, Android, BlackBerry, Palm, Symbian.wrt Android, Blackberry, navigator.contacts.find Symbian (filter, success, error, options); filter is an object of type Contact iPhone getAllContacts newContact chooseContact displayContact removeContact contactsCount
  • 21. Contacts o The most inconsistent between platforms o Test on devices, not just simulators!
  • 22. File iPhone, Android, BlackBerry, Palm, Symbian.wrt navigator.fileMgr FileReader object FileWriter object Palm webOS does not allow File I/O File.read is implemented with an XHR BlackBerry should be implemented... • use Store (see later slide) instead Android & iPhone: based loosely on W3C file spec: http://bit.ly/w3cfile example API usage: http://bit.ly/pg-file
  • 23. Media (Audio) iPhone, Android, BlackBerry, Palm, Symbian.wrt var mySong = new Media ("urthebest.mp3",success,error); mySong.play(); mySong.pause(); mySong.stop(); Blackberry, Palm and Symbian as Audio, not Media iPhone and Android can record audio also • iPhone: startAudioRecord, stopAudioRecord • Android: startRecord, stopRecordingAudio
  • 24. Storage/Store iPhone, Android, BlackBerry, Palm, Symbian.wrt iPhone/Android 2.0+/Palm: unneeded - use localStorage or HTML5 db Android < 2.0: sets up an SQLite database, accessed through window.openDatabase • Unstable: use with caution Symbian: key/value store: navigator.storage.getItem navigator.storage.setItem BlackBerry: key/value store: navigator.store.get navigator.store.put
  • 25. SMS/Telephony iPhone, Android, BlackBerry, Palm, Symbian.wrt navigator.sms.send(number, message, success, error, options); navigator.telephony.send(number); To be implemented on iPhone/Android Any platform: set link HREF to sms: or tel: In all cases, the user must confirm before the call or message is placed
  • 26. Questions or Feedback @alunny, andrew.lunny@nitobi.com