SlideShare a Scribd company logo
1 of 34
Download to read offline
Web Developer 的逆襲
Cordova (Phonegap) Plugin
加碼演出串接 Parse
2014/03/22 Marty
今天玩什麼?
1. Cordova CLI (create、add android、build)
2. GenyMotion (run Android app)
3. Install Cordova Plugin & Trace (camera)
4. How to write a Cordova Plugin
5. BaaS (Parse)
Web 經由 plugin 獲取超能力
1. Sensor
2. Native API
3. MultiThread
4. Connect anywhere Wifi(Http、TCP/IP)、Bluetooth
5. ...
環境要先安裝好
● Android SDK
● NodeJS
●
● GenyMotion
npm install cordova
cordova create hello com.example.hello HelloWorld
Create Android Project
目錄名稱
package Name
App Name
Step1:
cd helloStep2:
cordova platform add androidStep3:
$
$
$
WebView - 先天限制!
Android activity
install APK
cordova build$
cd platforms/android/ant-build$
adb install -r HelloWorld-debug.apk$
Step1:
Step2:
Step3:
沒有Android手機 ?
來來來,裝plugin
cordova plugin add org.apache.cordova.camera$
用 JQMDesigner 設計畫面,匯出 html
匯出HTML
更新 html 檔案 $project/www/index.html
改成用本地的
install APK - Camera
cordova build$
cd platforms/android/ant-build$
adb install -r HelloWorld-debug.apk$
Step1:
Step2:
Step3:
拍照 App
Youtube
來來來,來寫plugin
JavaScript invoke Java's Method
cordova.exec(
function(winParam) {},
function(error) {},
"service", "action",
["firstArgument", "secondArgument", 42,false]);
@Overridepublic boolean execute(String action, JSONArray args, CallbackContextcallbackContext) throws JSONException {if ("beep".equals(action)) {this.beep(args.getLong( 0));callbackContext.success();return true;}return false; // "MethodNotFound" error.}
JavaScript
Java
Success callback
cordova.exec(
function(winParam) {},
function(error) {},
"service", "action",
["firstArgument", "secondArgument", 42,false]);
@Overridepublic boolean execute(String action, JSONArray args, CallbackContextcallbackContext) throws JSONException {if ("beep".equals(action)) {this.beep(args.getLong( 0));callbackContext.success();return true;}return false; // "MethodNotFound" error.}
JavaScript
Java
Failure callback
cordova.exec(
function(winParam) {},
function(error) {},
"service", "action",
["firstArgument", "secondArgument", 42,false]);
@Overridepublic boolean execute(String action, JSONArray args, CallbackContextcallbackContext) throws JSONException {if ("beep".equals(action)) {this.beep(args.getLong( 0));callbackContext.success();return true;}return false; // "MethodNotFound" error.}
JavaScript
Java
getActivity().runOnUiThread(...)
@Override
public boolean execute(String action, JSONArray args, final
CallbackContext callbackContext) throws JSONException {
if ("beep".equals(action)) {
final long duration = args.getLong(0);
cordova.getActivity().runOnUiThread(new Runnable() {
public void run() {
...
callbackContext.success(); // Thread-safe.
}
});
return true;
}
return false;
}
與UI互動的事,通知
UiThread去安排執行
getThreadPool().execute(...)
@Overridepublic boolean execute(String action, JSONArray args, finalCallbackContext callbackContext) throws JSONException {if ("beep".equals(action)) {final long duration = args.getLong(0);cordova.getThreadPool().execute(new Runnable() {public void run() {...callbackContext.success(); // Thread-safe.}});return true;}return false;}
在ThreadPool做事,別阻礙
WebCore Thread
Camera code trace
trace camera
www/plugins/...camera/www/Camera.js
org.apache.cordova.camera.CameraLauncher
同時只能用一
個相機?
好了,開始自幹 Cordova plugin
先宣告,ServiceName、實作類別
記得 ServiceName、實作類別(含Class)
Service
Name
package.
Class
新增Echo類別
Copy & Read,了解參數傳遞和用法
繼承
action
找不到方法
回呼
成功 & 失敗
方法
在JS使用 cordova.exec(...)方法
一個plugin (Service) 可以有多種Action,Action攜帶JSONArray
exec(<successFunction>, <failFunction>,<service>, <action>, [<args>]);
$
config.xml
index.html
Echo.java
完成 Cordova plugin
BaaS (Backend as a Service)
先試試存資料...
用 Web API 串接 (Parse)
http://www.parsecdn.com/js/parse-1.2.18.min.js
Thanks , 一起玩吧!
● How to call back from java to javascript in cordova
● MOPCON 2013 Session + Parse

More Related Content

What's hot

Daniel Neumann Project Experience
Daniel Neumann Project ExperienceDaniel Neumann Project Experience
Daniel Neumann Project Experience
Daniel Neumann, PhD
 
Advanced operating system_ja_2_
Advanced operating system_ja_2_Advanced operating system_ja_2_
Advanced operating system_ja_2_
saitonorio
 
Advanced operating system_ja_2
Advanced operating system_ja_2Advanced operating system_ja_2
Advanced operating system_ja_2
saitonorio
 
After HTML5 Mobilism 2011
After HTML5 Mobilism 2011After HTML5 Mobilism 2011
After HTML5 Mobilism 2011
Brian LeRoux
 

What's hot (20)

MiTM Attacks in Android Apps - TDC 2014
MiTM Attacks in Android Apps - TDC 2014MiTM Attacks in Android Apps - TDC 2014
MiTM Attacks in Android Apps - TDC 2014
 
Angular Universal
Angular UniversalAngular Universal
Angular Universal
 
Hybrid mobile app with kendo ui mobile
Hybrid mobile app with kendo ui mobileHybrid mobile app with kendo ui mobile
Hybrid mobile app with kendo ui mobile
 
Cocoa for The Web
Cocoa for The WebCocoa for The Web
Cocoa for The Web
 
Hybrid Apps, Ionic framework
Hybrid Apps, Ionic frameworkHybrid Apps, Ionic framework
Hybrid Apps, Ionic framework
 
Intro to Mobile Development for Web iOS and Android
Intro to Mobile Development for Web iOS and AndroidIntro to Mobile Development for Web iOS and Android
Intro to Mobile Development for Web iOS and Android
 
Cocoa for The Web
Cocoa for The WebCocoa for The Web
Cocoa for The Web
 
Why Should Product Owners Go for Angular Web Development?
Why Should Product Owners Go for Angular Web Development?Why Should Product Owners Go for Angular Web Development?
Why Should Product Owners Go for Angular Web Development?
 
AngularJs advanced Topics
AngularJs advanced TopicsAngularJs advanced Topics
AngularJs advanced Topics
 
Shailender cv
Shailender cvShailender cv
Shailender cv
 
Introdução Ionic Framework - Meetup SP
Introdução Ionic Framework - Meetup SPIntrodução Ionic Framework - Meetup SP
Introdução Ionic Framework - Meetup SP
 
Daniel Neumann Project Experience
Daniel Neumann Project ExperienceDaniel Neumann Project Experience
Daniel Neumann Project Experience
 
Create HTML5 Mobile Apps for WordPress Site
Create HTML5 Mobile Apps for WordPress SiteCreate HTML5 Mobile Apps for WordPress Site
Create HTML5 Mobile Apps for WordPress Site
 
Advanced operating system_ja_2_
Advanced operating system_ja_2_Advanced operating system_ja_2_
Advanced operating system_ja_2_
 
Advanced operating system_ja_2
Advanced operating system_ja_2Advanced operating system_ja_2
Advanced operating system_ja_2
 
SwiftLint
SwiftLintSwiftLint
SwiftLint
 
After HTML5 Mobilism 2011
After HTML5 Mobilism 2011After HTML5 Mobilism 2011
After HTML5 Mobilism 2011
 
製作 Unity Plugin for Android
製作 Unity Plugin for Android製作 Unity Plugin for Android
製作 Unity Plugin for Android
 
React native sharing
React native sharingReact native sharing
React native sharing
 
Open Hack Taiwan 2012 - Mojito intro
Open Hack Taiwan 2012 - Mojito introOpen Hack Taiwan 2012 - Mojito intro
Open Hack Taiwan 2012 - Mojito intro
 

Viewers also liked

2014南部創新應用工具研討會 快速開發行動 app
2014南部創新應用工具研討會 快速開發行動 app2014南部創新應用工具研討會 快速開發行動 app
2014南部創新應用工具研討會 快速開發行動 app
益祥 許
 

Viewers also liked (9)

Jsdc 2013
Jsdc 2013Jsdc 2013
Jsdc 2013
 
PolymerJS 開發實戰
PolymerJS 開發實戰PolymerJS 開發實戰
PolymerJS 開發實戰
 
Webduino 新功能介紹體驗
Webduino 新功能介紹體驗Webduino 新功能介紹體驗
Webduino 新功能介紹體驗
 
2015 JSDC Build Anything with JavaScript
2015 JSDC Build Anything with JavaScript2015 JSDC Build Anything with JavaScript
2015 JSDC Build Anything with JavaScript
 
前端工程師的告白: 親愛的,開源的物聯網好好玩呀!
前端工程師的告白: 親愛的,開源的物聯網好好玩呀!前端工程師的告白: 親愛的,開源的物聯網好好玩呀!
前端工程師的告白: 親愛的,開源的物聯網好好玩呀!
 
2014南部創新應用工具研討會 快速開發行動 app
2014南部創新應用工具研討會 快速開發行動 app2014南部創新應用工具研討會 快速開發行動 app
2014南部創新應用工具研討會 快速開發行動 app
 
一拳前端考題
一拳前端考題一拳前端考題
一拳前端考題
 
2015 WebConf - Web + Arduino 實在有夠潮
2015 WebConf  - Web + Arduino 實在有夠潮2015 WebConf  - Web + Arduino 實在有夠潮
2015 WebConf - Web + Arduino 實在有夠潮
 
Web + Arduino 實在有夠潮 ( 課程簡報 )
Web + Arduino 實在有夠潮 ( 課程簡報 ) Web + Arduino 實在有夠潮 ( 課程簡報 )
Web + Arduino 實在有夠潮 ( 課程簡報 )
 

Similar to App開發 - Web Developer的逆襲

Parkjihoon phonegap research_for_bada
Parkjihoon phonegap research_for_badaParkjihoon phonegap research_for_bada
Parkjihoon phonegap research_for_bada
웹데브모바일
 
Open Web Device: The first phone running Firefox OS!
Open Web Device: The first phone running Firefox OS!Open Web Device: The first phone running Firefox OS!
Open Web Device: The first phone running Firefox OS!
Francisco Jordano
 

Similar to App開發 - Web Developer的逆襲 (20)

Mobile development in 2020
Mobile development in 2020 Mobile development in 2020
Mobile development in 2020
 
Getting Your Hooks Into Cordova
Getting Your Hooks Into CordovaGetting Your Hooks Into Cordova
Getting Your Hooks Into Cordova
 
Getting your Hooks into Cordova
Getting your Hooks into CordovaGetting your Hooks into Cordova
Getting your Hooks into Cordova
 
Getting Your Hooks into Cordova
Getting Your Hooks into CordovaGetting Your Hooks into Cordova
Getting Your Hooks into Cordova
 
Hybrid HTML5 Apps
Hybrid HTML5 AppsHybrid HTML5 Apps
Hybrid HTML5 Apps
 
Apache cordova
Apache cordovaApache cordova
Apache cordova
 
Creating mobile apps the web developer way
Creating mobile apps the web developer wayCreating mobile apps the web developer way
Creating mobile apps the web developer way
 
Cordova 3.x
Cordova 3.xCordova 3.x
Cordova 3.x
 
Apps with Apache Cordova and Phonegap
Apps with Apache Cordova and PhonegapApps with Apache Cordova and Phonegap
Apps with Apache Cordova and Phonegap
 
Cordova Tutorial
Cordova TutorialCordova Tutorial
Cordova Tutorial
 
Drone sdk showdown
Drone sdk showdownDrone sdk showdown
Drone sdk showdown
 
Multi-stage Docker builds to make building easy!
Multi-stage Docker builds to make building easy!Multi-stage Docker builds to make building easy!
Multi-stage Docker builds to make building easy!
 
PhoneGap Day 2016 USA
PhoneGap Day 2016 USAPhoneGap Day 2016 USA
PhoneGap Day 2016 USA
 
Parkjihoon phonegap research_for_bada
Parkjihoon phonegap research_for_badaParkjihoon phonegap research_for_bada
Parkjihoon phonegap research_for_bada
 
Cordova 101
Cordova 101Cordova 101
Cordova 101
 
OpenMIC March-2012.phonegap
OpenMIC March-2012.phonegapOpenMIC March-2012.phonegap
OpenMIC March-2012.phonegap
 
Phonegap android angualr material design
Phonegap android angualr material designPhonegap android angualr material design
Phonegap android angualr material design
 
Open Web Device: The first phone running Firefox OS!
Open Web Device: The first phone running Firefox OS!Open Web Device: The first phone running Firefox OS!
Open Web Device: The first phone running Firefox OS!
 
An overview of Ionic
An overview of IonicAn overview of Ionic
An overview of Ionic
 
PhoneGap - Now and the Future
PhoneGap - Now and the FuturePhoneGap - Now and the Future
PhoneGap - Now and the Future
 

Recently uploaded

Future Visions: Predictions to Guide and Time Tech Innovation, Peter Udo Diehl
Future Visions: Predictions to Guide and Time Tech Innovation, Peter Udo DiehlFuture Visions: Predictions to Guide and Time Tech Innovation, Peter Udo Diehl
Future Visions: Predictions to Guide and Time Tech Innovation, Peter Udo Diehl
Peter Udo Diehl
 
Structuring Teams and Portfolios for Success
Structuring Teams and Portfolios for SuccessStructuring Teams and Portfolios for Success
Structuring Teams and Portfolios for Success
UXDXConf
 

Recently uploaded (20)

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
 
IESVE for Early Stage Design and Planning
IESVE for Early Stage Design and PlanningIESVE for Early Stage Design and Planning
IESVE for Early Stage Design and Planning
 
Strategic AI Integration in Engineering Teams
Strategic AI Integration in Engineering TeamsStrategic AI Integration in Engineering Teams
Strategic AI Integration in Engineering Teams
 
Speed Wins: From Kafka to APIs in Minutes
Speed Wins: From Kafka to APIs in MinutesSpeed Wins: From Kafka to APIs in Minutes
Speed Wins: From Kafka to APIs in Minutes
 
The Metaverse: Are We There Yet?
The  Metaverse:    Are   We  There  Yet?The  Metaverse:    Are   We  There  Yet?
The Metaverse: Are We There Yet?
 
Connecting the Dots in Product Design at KAYAK
Connecting the Dots in Product Design at KAYAKConnecting the Dots in Product Design at KAYAK
Connecting the Dots in Product Design at KAYAK
 
Future Visions: Predictions to Guide and Time Tech Innovation, Peter Udo Diehl
Future Visions: Predictions to Guide and Time Tech Innovation, Peter Udo DiehlFuture Visions: Predictions to Guide and Time Tech Innovation, Peter Udo Diehl
Future Visions: Predictions to Guide and Time Tech Innovation, Peter Udo Diehl
 
Free and Effective: Making Flows Publicly Accessible, Yumi Ibrahimzade
Free and Effective: Making Flows Publicly Accessible, Yumi IbrahimzadeFree and Effective: Making Flows Publicly Accessible, Yumi Ibrahimzade
Free and Effective: Making Flows Publicly Accessible, Yumi Ibrahimzade
 
Syngulon - Selection technology May 2024.pdf
Syngulon - Selection technology May 2024.pdfSyngulon - Selection technology May 2024.pdf
Syngulon - Selection technology May 2024.pdf
 
ECS 2024 Teams Premium - Pretty Secure
ECS 2024   Teams Premium - Pretty SecureECS 2024   Teams Premium - Pretty Secure
ECS 2024 Teams Premium - Pretty Secure
 
FDO for Camera, Sensor and Networking Device – Commercial Solutions from VinC...
FDO for Camera, Sensor and Networking Device – Commercial Solutions from VinC...FDO for Camera, Sensor and Networking Device – Commercial Solutions from VinC...
FDO for Camera, Sensor and Networking Device – Commercial Solutions from VinC...
 
Oauth 2.0 Introduction and Flows with MuleSoft
Oauth 2.0 Introduction and Flows with MuleSoftOauth 2.0 Introduction and Flows with MuleSoft
Oauth 2.0 Introduction and Flows with MuleSoft
 
Structuring Teams and Portfolios for Success
Structuring Teams and Portfolios for SuccessStructuring Teams and Portfolios for Success
Structuring Teams and Portfolios for Success
 
The UX of Automation by AJ King, Senior UX Researcher, Ocado
The UX of Automation by AJ King, Senior UX Researcher, OcadoThe UX of Automation by AJ King, Senior UX Researcher, Ocado
The UX of Automation by AJ King, Senior UX Researcher, Ocado
 
Top 10 Symfony Development Companies 2024
Top 10 Symfony Development Companies 2024Top 10 Symfony Development Companies 2024
Top 10 Symfony Development Companies 2024
 
Where to Learn More About FDO _ Richard at FIDO Alliance.pdf
Where to Learn More About FDO _ Richard at FIDO Alliance.pdfWhere to Learn More About FDO _ Richard at FIDO Alliance.pdf
Where to Learn More About FDO _ Richard at FIDO Alliance.pdf
 
What's New in Teams Calling, Meetings and Devices April 2024
What's New in Teams Calling, Meetings and Devices April 2024What's New in Teams Calling, Meetings and Devices April 2024
What's New in Teams Calling, Meetings and Devices April 2024
 
SOQL 201 for Admins & Developers: Slice & Dice Your Org’s Data With Aggregate...
SOQL 201 for Admins & Developers: Slice & Dice Your Org’s Data With Aggregate...SOQL 201 for Admins & Developers: Slice & Dice Your Org’s Data With Aggregate...
SOQL 201 for Admins & Developers: Slice & Dice Your Org’s Data With Aggregate...
 
Measures in SQL (a talk at SF Distributed Systems meetup, 2024-05-22)
Measures in SQL (a talk at SF Distributed Systems meetup, 2024-05-22)Measures in SQL (a talk at SF Distributed Systems meetup, 2024-05-22)
Measures in SQL (a talk at SF Distributed Systems meetup, 2024-05-22)
 
A Business-Centric Approach to Design System Strategy
A Business-Centric Approach to Design System StrategyA Business-Centric Approach to Design System Strategy
A Business-Centric Approach to Design System Strategy
 

App開發 - Web Developer的逆襲