SlideShare uma empresa Scribd logo
1 de 16
Baixar para ler offline
PhoneGap JavaScript API
          Vs
  Native Components
       (Plugins)
Introduction

   PhoneGap is an open source implementation of open standards. That means
    developers and companies can use PhoneGap for mobile applications that
    are free, commercial, open source, or any combination of these.

   Building applications for each device–iPhone, Android, Windows Mobile and
    more- requires different frameworks and languages. PhoneGap bridges Web
    Applications and Mobile Devices using Standards-based Web technologies.
PhoneGap JavaScript API Vs Native Components (Plugins)

PhoneGap has two Components :

1.   The PhoneGap Core Libraries are designed to handle common tasks
     supported by most devices-

a)   Access geolocation from the PhoneGap JavaScript API

b)   Access contacts from the PhoneGap JavaScript API

c)   Invoke a call2. PhoneGap’s JavaScript API makes those common phone
     functions available to JavaScript to run in the Browser (Native WebView).
PhoneGap JavaScript API Vs Native Components (Plugins)

Along with its Cross-platform Advantage PhoneGap comes with following
     Limitations:
i)      Writing Javascript to do heavyweight data processing will typically be
        much slower than writing native code for the device and serving the
        results to a front-end.
ii)     If we want to do some background processing (e.g. background services
        in Android), Javascript cannot achieve it.
iii)    Similarly, if we plan to implement a very Complex Business Functionality,
        a preference would be given to the native language.

For such complex tasks, it is best to delegate the responsibility to Native
     Components.
PhoneGap JavaScript API Vs Native Components (Plugins)

Extend PhoneGap Framework – Create Native Components (Plugins)

The solution to the Limitations is to:1. Create a Custom Native Component
  (Plugin): This Native Component(Plugin) would be built for each platform
  you plan to support.2. Create a Custom Javascript API: All these Native
  Components (Plugins) needs to adhere to the Custom JavaScript API, which
  exposes their functionality to the JavaScript running in the Browser.
PhoneGap JavaScript API Vs Native Components (Plugins)

Thus, overall PhoneGap Architecture

becomes:
PhoneGap JavaScript API Vs Native Components (Plugins)

They are Not Cross Platform:

Suppose you are developing a PhoneGap Plugin for two platforms: iOS and
  Android, you need-

1.   One JavaScript file for Android, along with a Java file(Native Component)
     for Android.

2.   A different JavaScript file for iOS, along with pair of .h and .m files (Native
     Components) for iOS.Both JavaScript files can (and should) have the same
     interface for the developer who consumes it, but the implementations of
     each interface would be different.
PhoneGap JavaScript API Vs Native Components (Plugins)

Developing Android PhoneGap Plugin:

Regardless of which platform you begin developing with, following two methods play the key
  Role:

1. PluginResult.execute() is your core Native function: The JavaScript that you will write in
   your JS plugin will need to call Phonegap.exec (successCallback, failCallback, pluginName,
   action, [args]). That’s a JavaScript function, found in phonegap-version.x.x.js (or cordova-
   1.7.0rc1.jar or higher) that expects a function named “execute” on the Native Plugin side.

2. Phonegap.exec() is your core JS function: The Native Plugin need to define one call to
   Phonegap.exec() on the JS side.

“CopyImagesPlugin”: This plugin lets you copy any number of image resources form assets
  to the Device SD-Card.
PhoneGap JavaScript API Vs Native Components (Plugins)

Step 1: Create a new PhoneGap Project (along with all PhoneGap
  dependencies) using New Project Wizard in Eclipse. If You have not installed
  PhoneGap Development Addin to eclipse, then you can do it in following
  manner:

Open Eclipse -> Click on ‘Help’ on MenuBar-> ‘Install New Software’ ->

click on ‘Add’ button at new Window-> and copy following url to Location field:

https://svn.codespot.com/a/eclipselabs.org/mobile-web-development-with-
  phonegap/tags/r1.2/download
PhoneGap JavaScript API Vs Native Components (Plugins)

Give any name to Name Field. E.g. ‘Phonegap Addin Tool’

Click on ‘ok’ button this will start downloading al required Softwares.

Click ‘Next’ and finish the installation Wazard.

It will ask to Restart Eclipse and eclipce toolbar now includes PhoneGap icon as
   shown in below image:
PhoneGap JavaScript API Vs Native Components (Plugins)

Step 2: Implement the Plugin Class: “CopyToSdCard”

Code can be found here:

http://d.pr/n/CPyK
PhoneGap JavaScript API Vs Native Components (Plugins)

Step 3: Implement Plugin JavaScript

1. Create a file called copyToSdCard.js

2. In it create a class named CopyToSdCard.

3. Create a member function named copyFiles ().

4. In copyFiles () function call PhoneGap.exec(<>, <>,<>,<>,<>);

5. Finally register both CopyToSdCard class as an JavaScript Plugin and register Java Class as the native Plugin
    (invoked from Javascript)

Below is the complete Source code for copyToSdCard.js file:

Here: http://d.pr/n/cCGT
PhoneGap JavaScript API Vs Native Components (Plugins)

Installing Plugins for Android

On Android, the plugin Java source code needs to be included in your PhoneGap
  Android project either in source form or as a JAR library.In addition, the
  JavaScript for the plugin needs to be added to the ./assets/www/* folder of your
  PhoneGap Android project and linked in your HTML source code.Finally an
  additional element needs to be added to the ./res/xml/plugins.xml file. The
  plugins.xml file describes what plugins are allowed to be called from
  JavaScript.Step 4: Register plugin to res/xml/plugin.xml file:

<plugin name="CopyImagesPlugin" value="com.phonegap.plugins.test.
  CopyToSdCard"/>
PhoneGap JavaScript API Vs Native Components (Plugins)

Step 4: Register plugin to res/xml/plugin.xml file:

<plugin name="CopyImagesPlugin" value="com.phonegap.plugins.test.
  CopyToSdCard"/>

Step 5: Add following javascript reference to your html file:

<script type="text/javascript" charset="utf-8" src="copyToSdCard.js"></script>
PhoneGap JavaScript API Vs Native Components (Plugins)

Step 6: Add following javascript code to html file:

Code: http://d.pr/n/6xIg

Finally, call the above javascript method saveToSdFromAssets () from your Html file
  say on a button click as below:

<a href="javascript:void(0)" onclick="saveToSdFromAssets();" data-role="button"
  data-theme="a" value='Save to SD Card' width='50%' >Save to SD Card</a>

Similarly, The same plugin can be developed for iOS and other mobile Platforms in
  respective Native Language (in case of android its Java).
At TechAhead, we have experience of creating cross platform mobile apps for
our clients. If you have any requirement for cross platform mobile application
development, contact us on info@techaheadcorp.com for FREE 30 minutes no
obligation consultation with our mobile apps experts($200 Value).




                                                                          5/11/2012

Mais conteúdo relacionado

Mais procurados

MDC2011 Android_ Webdriver Automation Test
MDC2011 Android_ Webdriver Automation TestMDC2011 Android_ Webdriver Automation Test
MDC2011 Android_ Webdriver Automation Test
Masud Parvez
 
Paragon New and Old Comparassion
Paragon New and Old ComparassionParagon New and Old Comparassion
Paragon New and Old Comparassion
Mark Flavin
 

Mais procurados (20)

MDC2011 Android_ Webdriver Automation Test
MDC2011 Android_ Webdriver Automation TestMDC2011 Android_ Webdriver Automation Test
MDC2011 Android_ Webdriver Automation Test
 
Angular 9 New features
Angular 9 New featuresAngular 9 New features
Angular 9 New features
 
Google closure compiler
Google closure compilerGoogle closure compiler
Google closure compiler
 
M365 global developer bootcamp 2019
M365 global developer bootcamp 2019M365 global developer bootcamp 2019
M365 global developer bootcamp 2019
 
Refactoring Wunderlist. UA Mobile 2016.
Refactoring Wunderlist. UA Mobile 2016.Refactoring Wunderlist. UA Mobile 2016.
Refactoring Wunderlist. UA Mobile 2016.
 
Modern web app with REACT
Modern web app with REACTModern web app with REACT
Modern web app with REACT
 
ユニバーサル Windows アプリ開発
ユニバーサル Windows アプリ開発ユニバーサル Windows アプリ開発
ユニバーサル Windows アプリ開発
 
Developing Native Mobile Apps Using JavaScript, ApacheCon NA 2014
Developing Native Mobile Apps Using JavaScript, ApacheCon NA 2014Developing Native Mobile Apps Using JavaScript, ApacheCon NA 2014
Developing Native Mobile Apps Using JavaScript, ApacheCon NA 2014
 
Paragon New and Old Comparassion
Paragon New and Old ComparassionParagon New and Old Comparassion
Paragon New and Old Comparassion
 
Ng2 cli
Ng2 cliNg2 cli
Ng2 cli
 
Flash Testing with Selenium RC
Flash Testing with Selenium RCFlash Testing with Selenium RC
Flash Testing with Selenium RC
 
[JavaLand 2015] Developing JavaScript Mobile Apps Using Apache Cordova
[JavaLand 2015] Developing JavaScript Mobile Apps Using Apache Cordova[JavaLand 2015] Developing JavaScript Mobile Apps Using Apache Cordova
[JavaLand 2015] Developing JavaScript Mobile Apps Using Apache Cordova
 
‘Hello, world!’ application how to dockerize golang application
‘Hello, world!’ application how to dockerize golang application‘Hello, world!’ application how to dockerize golang application
‘Hello, world!’ application how to dockerize golang application
 
Applet programming1
Applet programming1Applet programming1
Applet programming1
 
Mobile Automation with Appium
Mobile Automation with AppiumMobile Automation with Appium
Mobile Automation with Appium
 
Continous UI testing with Espresso and Jenkins
Continous UI testing with Espresso and JenkinsContinous UI testing with Espresso and Jenkins
Continous UI testing with Espresso and Jenkins
 
[INNOVATUBE] Tech Talk #3: Golang - Takaaki Mizuno
 [INNOVATUBE] Tech Talk #3: Golang - Takaaki Mizuno [INNOVATUBE] Tech Talk #3: Golang - Takaaki Mizuno
[INNOVATUBE] Tech Talk #3: Golang - Takaaki Mizuno
 
API Testing following the Test Pyramid
API Testing following the Test PyramidAPI Testing following the Test Pyramid
API Testing following the Test Pyramid
 
Creating a comp
Creating a compCreating a comp
Creating a comp
 
How to configure monkey talk android agent
How to configure monkey talk android agentHow to configure monkey talk android agent
How to configure monkey talk android agent
 

Destaque

PhoneGap @ Javascript Directions
PhoneGap @ Javascript DirectionsPhoneGap @ Javascript Directions
PhoneGap @ Javascript Directions
Tiang Cheng
 
Desarrollo de Apps con la herramienta Phonegap
Desarrollo de Apps con la herramienta PhonegapDesarrollo de Apps con la herramienta Phonegap
Desarrollo de Apps con la herramienta Phonegap
CongresoWeb
 
A proposal for elderly frailty detection by using accelerometer-enabled smart...
A proposal for elderly frailty detection by using accelerometer-enabled smart...A proposal for elderly frailty detection by using accelerometer-enabled smart...
A proposal for elderly frailty detection by using accelerometer-enabled smart...
Jesús Fontecha
 
Internet of Things. Definition of a concept
Internet of Things. Definition of a conceptInternet of Things. Definition of a concept
Internet of Things. Definition of a concept
Jesús Fontecha
 

Destaque (14)

PhoneGap in 60 Minutes or Less
PhoneGap in 60 Minutes or LessPhoneGap in 60 Minutes or Less
PhoneGap in 60 Minutes or Less
 
PhoneGap @ Javascript Directions
PhoneGap @ Javascript DirectionsPhoneGap @ Javascript Directions
PhoneGap @ Javascript Directions
 
PhoneGap - JavaScript for Mobile Apps
PhoneGap - JavaScript for Mobile AppsPhoneGap - JavaScript for Mobile Apps
PhoneGap - JavaScript for Mobile Apps
 
PhoneGap Basics v1.0
PhoneGap Basics v1.0PhoneGap Basics v1.0
PhoneGap Basics v1.0
 
Android Basics v2.5
Android Basics v2.5Android Basics v2.5
Android Basics v2.5
 
A Sensorized and Health aspect-based framework to improve the continuous moni...
A Sensorized and Health aspect-based framework to improve the continuous moni...A Sensorized and Health aspect-based framework to improve the continuous moni...
A Sensorized and Health aspect-based framework to improve the continuous moni...
 
Context-aware and user centered evaluation of assistive systems
Context-aware and user centered evaluation of assistive systemsContext-aware and user centered evaluation of assistive systems
Context-aware and user centered evaluation of assistive systems
 
Android basics v3
Android basics v3Android basics v3
Android basics v3
 
Learn javascript easy steps
Learn javascript easy stepsLearn javascript easy steps
Learn javascript easy steps
 
Brújula, Acelerómetro y Geolocalización con PhoneGap (Básico)
Brújula, Acelerómetro y Geolocalización con PhoneGap (Básico)Brújula, Acelerómetro y Geolocalización con PhoneGap (Básico)
Brújula, Acelerómetro y Geolocalización con PhoneGap (Básico)
 
Exploring the AmIHEALTH paradigm. Monitoring in Healthcare: Building mHealth ...
Exploring the AmIHEALTH paradigm. Monitoring in Healthcare: Building mHealth ...Exploring the AmIHEALTH paradigm. Monitoring in Healthcare: Building mHealth ...
Exploring the AmIHEALTH paradigm. Monitoring in Healthcare: Building mHealth ...
 
Desarrollo de Apps con la herramienta Phonegap
Desarrollo de Apps con la herramienta PhonegapDesarrollo de Apps con la herramienta Phonegap
Desarrollo de Apps con la herramienta Phonegap
 
A proposal for elderly frailty detection by using accelerometer-enabled smart...
A proposal for elderly frailty detection by using accelerometer-enabled smart...A proposal for elderly frailty detection by using accelerometer-enabled smart...
A proposal for elderly frailty detection by using accelerometer-enabled smart...
 
Internet of Things. Definition of a concept
Internet of Things. Definition of a conceptInternet of Things. Definition of a concept
Internet of Things. Definition of a concept
 

Semelhante a PhoneGap JavaScript API vs Native Components

Android SDK and PhoneGap
Android SDK and PhoneGapAndroid SDK and PhoneGap
Android SDK and PhoneGap
Doncho Minkov
 
"Native" Apps with APEX and PhoneGap
"Native" Apps with APEX and PhoneGap"Native" Apps with APEX and PhoneGap
"Native" Apps with APEX and PhoneGap
Christian Rokitta
 
Parkjihoon phonegap research_for_bada
Parkjihoon phonegap research_for_badaParkjihoon phonegap research_for_bada
Parkjihoon phonegap research_for_bada
웹데브모바일
 

Semelhante a PhoneGap JavaScript API vs Native Components (20)

PhoneGap
PhoneGapPhoneGap
PhoneGap
 
Codename one
Codename oneCodename one
Codename one
 
Android SDK and PhoneGap
Android SDK and PhoneGapAndroid SDK and PhoneGap
Android SDK and PhoneGap
 
Phone gap
Phone gapPhone gap
Phone gap
 
Intro to PhoneGap
Intro to PhoneGapIntro to PhoneGap
Intro to PhoneGap
 
Getting Acquainted with PhoneGap
Getting Acquainted with PhoneGapGetting Acquainted with PhoneGap
Getting Acquainted with PhoneGap
 
Phone gap development, testing, and debugging
Phone gap development, testing, and debuggingPhone gap development, testing, and debugging
Phone gap development, testing, and debugging
 
phonegap_101
phonegap_101phonegap_101
phonegap_101
 
Introduction phonegap
Introduction phonegapIntroduction phonegap
Introduction phonegap
 
Advanced programing in phonegap
Advanced programing in phonegapAdvanced programing in phonegap
Advanced programing in phonegap
 
mobicon_paper
mobicon_papermobicon_paper
mobicon_paper
 
Intro to PhoneGap
Intro to PhoneGapIntro to PhoneGap
Intro to PhoneGap
 
"Native" Apps with APEX and PhoneGap
"Native" Apps with APEX and PhoneGap"Native" Apps with APEX and PhoneGap
"Native" Apps with APEX and PhoneGap
 
GDG Devfest 2016 session on Android N
GDG Devfest 2016 session on Android NGDG Devfest 2016 session on Android N
GDG Devfest 2016 session on Android N
 
Developing Mobile Application using Phonegap
Developing Mobile Application using PhonegapDeveloping Mobile Application using Phonegap
Developing Mobile Application using Phonegap
 
Google Glass Mirror API Setup
Google Glass Mirror API SetupGoogle Glass Mirror API Setup
Google Glass Mirror API Setup
 
Mobile development in 2020
Mobile development in 2020 Mobile development in 2020
Mobile development in 2020
 
Phone gap development, testing, and debugging
Phone gap development, testing, and debuggingPhone gap development, testing, and debugging
Phone gap development, testing, and debugging
 
Appium solution
Appium solutionAppium solution
Appium solution
 
Parkjihoon phonegap research_for_bada
Parkjihoon phonegap research_for_badaParkjihoon phonegap research_for_bada
Parkjihoon phonegap research_for_bada
 

Mais de TechAhead

Sneak Peek at Google I/O 2014 Highlights
Sneak Peek at Google I/O 2014 HighlightsSneak Peek at Google I/O 2014 Highlights
Sneak Peek at Google I/O 2014 Highlights
TechAhead
 
Top-Notch Slimmest Smartphones on Earth
Top-Notch Slimmest Smartphones on EarthTop-Notch Slimmest Smartphones on Earth
Top-Notch Slimmest Smartphones on Earth
TechAhead
 

Mais de TechAhead (20)

Most popular iPad is more of a Laptop now
Most popular iPad is more of a Laptop nowMost popular iPad is more of a Laptop now
Most popular iPad is more of a Laptop now
 
PWA vs Hybrid App vs Native: Which One Should You Choose?
PWA vs Hybrid App vs Native: Which One Should You Choose?PWA vs Hybrid App vs Native: Which One Should You Choose?
PWA vs Hybrid App vs Native: Which One Should You Choose?
 
What’s Behind the Success of Kayla Itsines’ Sweat App, Raking in $77 Million?
What’s Behind the Success of Kayla Itsines’ Sweat App, Raking in $77 Million?What’s Behind the Success of Kayla Itsines’ Sweat App, Raking in $77 Million?
What’s Behind the Success of Kayla Itsines’ Sweat App, Raking in $77 Million?
 
Revolutionary IoT App Ideas for the Near Future
Revolutionary IoT App Ideas for the Near FutureRevolutionary IoT App Ideas for the Near Future
Revolutionary IoT App Ideas for the Near Future
 
The Eight Building Blocks of Enterprise Application Architecture
The Eight Building Blocks of Enterprise Application ArchitectureThe Eight Building Blocks of Enterprise Application Architecture
The Eight Building Blocks of Enterprise Application Architecture
 
Get your Health Care Mobile App Discovered!
Get your Health Care Mobile App Discovered!Get your Health Care Mobile App Discovered!
Get your Health Care Mobile App Discovered!
 
Location-based Technologies Explained
Location-based Technologies ExplainedLocation-based Technologies Explained
Location-based Technologies Explained
 
11 Mobile App Retention Strategies for 2016
11 Mobile App Retention Strategies for 201611 Mobile App Retention Strategies for 2016
11 Mobile App Retention Strategies for 2016
 
10 Principles of Mobile App Design
10 Principles of Mobile App Design10 Principles of Mobile App Design
10 Principles of Mobile App Design
 
10 Conditions for Cost Estimation of an iOS Application
10 Conditions for Cost Estimation of an iOS Application10 Conditions for Cost Estimation of an iOS Application
10 Conditions for Cost Estimation of an iOS Application
 
7 Things About iPhone 6 Health App
7 Things About iPhone 6 Health App7 Things About iPhone 6 Health App
7 Things About iPhone 6 Health App
 
Google Apps for Work
Google Apps for WorkGoogle Apps for Work
Google Apps for Work
 
Meet the New Amazing Google Calendar App
Meet the New Amazing Google Calendar AppMeet the New Amazing Google Calendar App
Meet the New Amazing Google Calendar App
 
A Kickstarter's Guide to ICC Cricket World Cup 2015
A Kickstarter's Guide to ICC Cricket World Cup 2015A Kickstarter's Guide to ICC Cricket World Cup 2015
A Kickstarter's Guide to ICC Cricket World Cup 2015
 
Five Tech Masterpieces faded away in 2014
Five Tech Masterpieces faded away in 2014Five Tech Masterpieces faded away in 2014
Five Tech Masterpieces faded away in 2014
 
What makes Xiaomi's MIUI 6, The Eyeball Grabber in the mobile Industry?
What makes Xiaomi's MIUI 6, The Eyeball Grabber in the mobile Industry?What makes Xiaomi's MIUI 6, The Eyeball Grabber in the mobile Industry?
What makes Xiaomi's MIUI 6, The Eyeball Grabber in the mobile Industry?
 
Sneak Peek at Google I/O 2014 Highlights
Sneak Peek at Google I/O 2014 HighlightsSneak Peek at Google I/O 2014 Highlights
Sneak Peek at Google I/O 2014 Highlights
 
What makes iOS 8 the world’s most advanced mobile operating system?
What makes iOS 8 the world’s most advanced mobile operating system?What makes iOS 8 the world’s most advanced mobile operating system?
What makes iOS 8 the world’s most advanced mobile operating system?
 
Top-Notch Slimmest Smartphones on Earth
Top-Notch Slimmest Smartphones on EarthTop-Notch Slimmest Smartphones on Earth
Top-Notch Slimmest Smartphones on Earth
 
Windows 8.1 Tweaks & New Add-Ons
Windows 8.1 Tweaks & New Add-OnsWindows 8.1 Tweaks & New Add-Ons
Windows 8.1 Tweaks & New Add-Ons
 

Último

IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
Enterprise Knowledge
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
Earley Information Science
 

Último (20)

A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
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
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
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
 
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
 
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
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
[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
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
 

PhoneGap JavaScript API vs Native Components

  • 1. PhoneGap JavaScript API Vs Native Components (Plugins)
  • 2. Introduction  PhoneGap is an open source implementation of open standards. That means developers and companies can use PhoneGap for mobile applications that are free, commercial, open source, or any combination of these.  Building applications for each device–iPhone, Android, Windows Mobile and more- requires different frameworks and languages. PhoneGap bridges Web Applications and Mobile Devices using Standards-based Web technologies.
  • 3. PhoneGap JavaScript API Vs Native Components (Plugins) PhoneGap has two Components : 1. The PhoneGap Core Libraries are designed to handle common tasks supported by most devices- a) Access geolocation from the PhoneGap JavaScript API b) Access contacts from the PhoneGap JavaScript API c) Invoke a call2. PhoneGap’s JavaScript API makes those common phone functions available to JavaScript to run in the Browser (Native WebView).
  • 4. PhoneGap JavaScript API Vs Native Components (Plugins) Along with its Cross-platform Advantage PhoneGap comes with following Limitations: i) Writing Javascript to do heavyweight data processing will typically be much slower than writing native code for the device and serving the results to a front-end. ii) If we want to do some background processing (e.g. background services in Android), Javascript cannot achieve it. iii) Similarly, if we plan to implement a very Complex Business Functionality, a preference would be given to the native language. For such complex tasks, it is best to delegate the responsibility to Native Components.
  • 5. PhoneGap JavaScript API Vs Native Components (Plugins) Extend PhoneGap Framework – Create Native Components (Plugins) The solution to the Limitations is to:1. Create a Custom Native Component (Plugin): This Native Component(Plugin) would be built for each platform you plan to support.2. Create a Custom Javascript API: All these Native Components (Plugins) needs to adhere to the Custom JavaScript API, which exposes their functionality to the JavaScript running in the Browser.
  • 6. PhoneGap JavaScript API Vs Native Components (Plugins) Thus, overall PhoneGap Architecture becomes:
  • 7. PhoneGap JavaScript API Vs Native Components (Plugins) They are Not Cross Platform: Suppose you are developing a PhoneGap Plugin for two platforms: iOS and Android, you need- 1. One JavaScript file for Android, along with a Java file(Native Component) for Android. 2. A different JavaScript file for iOS, along with pair of .h and .m files (Native Components) for iOS.Both JavaScript files can (and should) have the same interface for the developer who consumes it, but the implementations of each interface would be different.
  • 8. PhoneGap JavaScript API Vs Native Components (Plugins) Developing Android PhoneGap Plugin: Regardless of which platform you begin developing with, following two methods play the key Role: 1. PluginResult.execute() is your core Native function: The JavaScript that you will write in your JS plugin will need to call Phonegap.exec (successCallback, failCallback, pluginName, action, [args]). That’s a JavaScript function, found in phonegap-version.x.x.js (or cordova- 1.7.0rc1.jar or higher) that expects a function named “execute” on the Native Plugin side. 2. Phonegap.exec() is your core JS function: The Native Plugin need to define one call to Phonegap.exec() on the JS side. “CopyImagesPlugin”: This plugin lets you copy any number of image resources form assets to the Device SD-Card.
  • 9. PhoneGap JavaScript API Vs Native Components (Plugins) Step 1: Create a new PhoneGap Project (along with all PhoneGap dependencies) using New Project Wizard in Eclipse. If You have not installed PhoneGap Development Addin to eclipse, then you can do it in following manner: Open Eclipse -> Click on ‘Help’ on MenuBar-> ‘Install New Software’ -> click on ‘Add’ button at new Window-> and copy following url to Location field: https://svn.codespot.com/a/eclipselabs.org/mobile-web-development-with- phonegap/tags/r1.2/download
  • 10. PhoneGap JavaScript API Vs Native Components (Plugins) Give any name to Name Field. E.g. ‘Phonegap Addin Tool’ Click on ‘ok’ button this will start downloading al required Softwares. Click ‘Next’ and finish the installation Wazard. It will ask to Restart Eclipse and eclipce toolbar now includes PhoneGap icon as shown in below image:
  • 11. PhoneGap JavaScript API Vs Native Components (Plugins) Step 2: Implement the Plugin Class: “CopyToSdCard” Code can be found here: http://d.pr/n/CPyK
  • 12. PhoneGap JavaScript API Vs Native Components (Plugins) Step 3: Implement Plugin JavaScript 1. Create a file called copyToSdCard.js 2. In it create a class named CopyToSdCard. 3. Create a member function named copyFiles (). 4. In copyFiles () function call PhoneGap.exec(<>, <>,<>,<>,<>); 5. Finally register both CopyToSdCard class as an JavaScript Plugin and register Java Class as the native Plugin (invoked from Javascript) Below is the complete Source code for copyToSdCard.js file: Here: http://d.pr/n/cCGT
  • 13. PhoneGap JavaScript API Vs Native Components (Plugins) Installing Plugins for Android On Android, the plugin Java source code needs to be included in your PhoneGap Android project either in source form or as a JAR library.In addition, the JavaScript for the plugin needs to be added to the ./assets/www/* folder of your PhoneGap Android project and linked in your HTML source code.Finally an additional element needs to be added to the ./res/xml/plugins.xml file. The plugins.xml file describes what plugins are allowed to be called from JavaScript.Step 4: Register plugin to res/xml/plugin.xml file: <plugin name="CopyImagesPlugin" value="com.phonegap.plugins.test. CopyToSdCard"/>
  • 14. PhoneGap JavaScript API Vs Native Components (Plugins) Step 4: Register plugin to res/xml/plugin.xml file: <plugin name="CopyImagesPlugin" value="com.phonegap.plugins.test. CopyToSdCard"/> Step 5: Add following javascript reference to your html file: <script type="text/javascript" charset="utf-8" src="copyToSdCard.js"></script>
  • 15. PhoneGap JavaScript API Vs Native Components (Plugins) Step 6: Add following javascript code to html file: Code: http://d.pr/n/6xIg Finally, call the above javascript method saveToSdFromAssets () from your Html file say on a button click as below: <a href="javascript:void(0)" onclick="saveToSdFromAssets();" data-role="button" data-theme="a" value='Save to SD Card' width='50%' >Save to SD Card</a> Similarly, The same plugin can be developed for iOS and other mobile Platforms in respective Native Language (in case of android its Java).
  • 16. At TechAhead, we have experience of creating cross platform mobile apps for our clients. If you have any requirement for cross platform mobile application development, contact us on info@techaheadcorp.com for FREE 30 minutes no obligation consultation with our mobile apps experts($200 Value). 5/11/2012