SlideShare a Scribd company logo
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

PPTX
How to build your own Hybrid JS Interface with Android?
PDF
Ionic adventures - Hybrid Mobile App Development rocks
PPTX
Intro to PhoneGap and PhoneGap Build
PDF
つくろう!Firefox OS アプリ
PDF
JavaScript : One To Many
PDF
Building Cross-Platform Mobile Apps
PDF
Building data driven mobile apps with phone gap and webapi
PPTX
Choosing the Right Mobile Development Platform (Part 2)
How to build your own Hybrid JS Interface with Android?
Ionic adventures - Hybrid Mobile App Development rocks
Intro to PhoneGap and PhoneGap Build
つくろう!Firefox OS アプリ
JavaScript : One To Many
Building Cross-Platform Mobile Apps
Building data driven mobile apps with phone gap and webapi
Choosing the Right Mobile Development Platform (Part 2)

What's hot (20)

ODP
MiTM Attacks in Android Apps - TDC 2014
PPTX
Angular Universal
PPTX
Hybrid mobile app with kendo ui mobile
PDF
Cocoa for The Web
PDF
Hybrid Apps, Ionic framework
PPTX
Intro to Mobile Development for Web iOS and Android
PDF
Cocoa for The Web
PDF
Why Should Product Owners Go for Angular Web Development?
PPTX
AngularJs advanced Topics
DOCX
Shailender cv
PPTX
Introdução Ionic Framework - Meetup SP
DOCX
Daniel Neumann Project Experience
PDF
Create HTML5 Mobile Apps for WordPress Site
PPTX
Advanced operating system_ja_2_
PPT
Advanced operating system_ja_2
PDF
SwiftLint
KEY
After HTML5 Mobilism 2011
PDF
製作 Unity Plugin for Android
PDF
React native sharing
KEY
Open Hack Taiwan 2012 - Mojito intro
MiTM Attacks in Android Apps - TDC 2014
Angular Universal
Hybrid mobile app with kendo ui mobile
Cocoa for The Web
Hybrid Apps, Ionic framework
Intro to Mobile Development for Web iOS and Android
Cocoa for The Web
Why Should Product Owners Go for Angular Web Development?
AngularJs advanced Topics
Shailender cv
Introdução Ionic Framework - Meetup SP
Daniel Neumann Project Experience
Create HTML5 Mobile Apps for WordPress Site
Advanced operating system_ja_2_
Advanced operating system_ja_2
SwiftLint
After HTML5 Mobilism 2011
製作 Unity Plugin for Android
React native sharing
Open Hack Taiwan 2012 - Mojito intro
Ad

Viewers also liked (9)

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

Recently uploaded (20)

PDF
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
PDF
Advanced methodologies resolving dimensionality complications for autism neur...
PDF
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
PDF
KodekX | Application Modernization Development
PDF
The Rise and Fall of 3GPP – Time for a Sabbatical?
PDF
Unlocking AI with Model Context Protocol (MCP)
PDF
Empathic Computing: Creating Shared Understanding
PDF
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
PDF
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
PDF
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
PPTX
sap open course for s4hana steps from ECC to s4
PPTX
Big Data Technologies - Introduction.pptx
PPTX
Digital-Transformation-Roadmap-for-Companies.pptx
PPT
“AI and Expert System Decision Support & Business Intelligence Systems”
DOCX
The AUB Centre for AI in Media Proposal.docx
PDF
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
PPTX
Cloud computing and distributed systems.
PDF
Chapter 3 Spatial Domain Image Processing.pdf
PDF
Network Security Unit 5.pdf for BCA BBA.
PDF
Approach and Philosophy of On baking technology
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
Advanced methodologies resolving dimensionality complications for autism neur...
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
KodekX | Application Modernization Development
The Rise and Fall of 3GPP – Time for a Sabbatical?
Unlocking AI with Model Context Protocol (MCP)
Empathic Computing: Creating Shared Understanding
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
sap open course for s4hana steps from ECC to s4
Big Data Technologies - Introduction.pptx
Digital-Transformation-Roadmap-for-Companies.pptx
“AI and Expert System Decision Support & Business Intelligence Systems”
The AUB Centre for AI in Media Proposal.docx
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
Cloud computing and distributed systems.
Chapter 3 Spatial Domain Image Processing.pdf
Network Security Unit 5.pdf for BCA BBA.
Approach and Philosophy of On baking technology

App開發 - Web Developer的逆襲