[Phonegap+Sencha Touch] 移动开发2、PhoneGap/Cordova初步使用

原文地址:http://blog.csdn.net/lovelyelfpop/article/details/20392249


下面讲的是创建一个PhoneGap/Corodva项目,然后打包成apk安装包 的一般方法。与以后讲Sencha touch+PhoneGap/Corodva的开发有少许不同。

1、打开cmd,把盘符转到想要创建项目的目录,比如 
D:\


2、创建项目
运行命令:
phonegap create hello com.pushsoft.hello Hello
cordova create hello com.pushsoft.hello Hello
第一个hello是项目文件夹名,此处就是D:\hello,在此文件夹下会生成www子目录作为主页面存入目录,包括有css,js和img资源。 其中config.xml包括了重要的资源描述和项目配置信息.
com.pushsoft.hello是包名,即命名空间,学过java的应该都知道,这个参数是可选的
第三个Hello是程序(app)名字


3、后续操作都要在创建的项目目录下进行,执行:
cd hello


4、编译
运行build命令,输入不同平台标识,生成不同平台下的相应文件。
如下以android设备为例:
D:\hello> phonegap build android
D:\hello> cordova platform add android
D:\hello> cordova build android

要查看详细(verbose)执行过程,可增加命令参数-V :
D:\hello> phonegap -V build android
D:\hello> cordova platform add android
D:\hello> cordova -V build android
之后可以看到D:\hello\platforms\android里出现Android项目,这个项目可以用eclipse或android  studio打开。


5 、编译并运行(相当于上面build和install两步骤操作)
D:\hello> phonegap run android
D:\hello> cordova run android

也可用参数e专门指定运行在模块器上:
D:\hello> phonegap -e run android
D:\hello> cordova -e run android




附录:如果需要为webapp提供一些调用原生api或设备的功能,比如摄像头、电池信息、访问文件、读取通讯录等,需要为phongap项目添加phonegap插件。
添加插件的方法(确保已经安装了Git)
cmd执行下面的命令,即可添加对应功能的插件,下面是官方完整的插件列表,我直接拷贝过来,可能会有变化:


Basic device information 基本设备信息:
phonegap local plugin add http://git-wip-us.apache.org/repos/asf/cordova-plugin-device.git

Network and battery status 网络和电池状态:
phonegap local plugin add http://git-wip-us.apache.org/repos/asf/cordova-plugin-network-information.git
phonegap local plugin add http://git-wip-us.apache.org/repos/asf/cordova-plugin-battery-status.git

Accelerometer, compass, and geolocation 加速度计、指南针和地理位置:
phonegap local plugin add http://git-wip-us.apache.org/repos/asf/cordova-plugin-device-motion.git
phonegap local plugin add http://git-wip-us.apache.org/repos/asf/cordova-plugin-device-orientation.git
phonegap local plugin add http://git-wip-us.apache.org/repos/asf/cordova-plugin-geolocation.git

Camera, media capture, and media playback 摄像头、网页摄像头和多媒体播放:
phonegap local plugin add http://git-wip-us.apache.org/repos/asf/cordova-plugin-camera.git
phonegap local plugin add http://git-wip-us.apache.org/repos/asf/cordova-plugin-media-capture.git
phonegap local plugin add http://git-wip-us.apache.org/repos/asf/cordova-plugin-media.git

Access files on device or network 访问本地或网络文件:
phonegap local plugin add http://git-wip-us.apache.org/repos/asf/cordova-plugin-file.git
phonegap local plugin add http://git-wip-us.apache.org/repos/asf/cordova-plugin-file-transfer.git

Notifications via dialog box or vibration 提示框通知或震动:
phonegap local plugin add http://git-wip-us.apache.org/repos/asf/cordova-plugin-dialogs.git
phonegap local plugin add http://git-wip-us.apache.org/repos/asf/cordova-plugin-vibration.git

Contacts 通讯录:
phonegap local plugin add http://git-wip-us.apache.org/repos/asf/cordova-plugin-contacts.git

Globalization 全球化 多语言:
phonegap local plugin add http://git-wip-us.apache.org/repos/asf/cordova-plugin-globalization.git

Splash Screen 启动画面:
phonegap local plugin add http://git-wip-us.apache.org/repos/asf/cordova-plugin-splashscreen.git

In-app browser App内嵌浏览器:
phonegap local plugin add http://git-wip-us.apache.org/repos/asf/cordova-plugin-inappbrowser.git

Debug console 调试控制台:
phonegap local plugin add http://git-wip-us.apache.org/repos/asf/cordova-plugin-console.git    


下面是一些非官方的插件:
  • 条形码

    • phonegap/phonegap-plugin-barcodescanner

    • Scandit/BarcodeScannerPlugin

  • 百度定位

    • PhoneGap3.0 使用百度地图SDK定位

    • DoubleSpout/phonegap_baidu_sdk_location

  • 安卓自动更新

    • phonegap更新插件

    • post2000/androidUpdatePlugin

  • 手写签名

    • cordova-plugin-signature-view

    • netinhoteixeira/cordova-plugin-signature-view

  • 推送

    • phonegap-build/PushPlugin

    • mrwutong/cordova-qdc-baidu-push

  • 选择文件或图片

    • don/cordova-filechooser

    • albertut/cordova-filepicker

    • wymsee/cordova-imagePicker


  • Toast提示 - Toast-PhoneGap-Plugin

  • 工具类 - Wizcorp/phonegap-plugin-wizUtils

  • 本地通知 - katzer/cordova-plugin-local-notifications · GitHub

  • 列表选择 - roberthovhannisyan/PhoneGap-Plugin-ListPicker · GitHub

  • 打开文件 - pwlin/cordova-plugin-file-opener2

  • 图片缩放 - RaananW/PhoneGap-Image-Resizer

  • 保存图片到相册 - grnadav/SaveToPhotoAlbumPhonegapPlugin

  • 日期选择器 - VitaliiBlagodir/cordova-plugin-datepicker

  • 屏幕方向 - yoik/cordova-yoik-screenorientation

  • SQLite - brodysoft/Cordova-SQLitePlugin

  • 键盘 - driftyco/ionic-plugins-keyboard

  • 封装了File的操作类 - torrmal/cordova-simplefilemanagement

  • WebIntent - Initsogar/cordova-webintent

  • 联系人选择 - hazemhagrass/ContactPicker

  • ActionSheet - EddyVerbruggen/cordova-plugin-actionsheet




欢迎加入Sencha Touch + Phonegap交流群

1群:194182999 (满)

2群:419834979

共同学习交流(博主QQ:479858761)


你可能感兴趣的:(android,移动开发,Build,PhoneGap,PhoneGap,sencha)