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

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

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

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

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

4、编译
运行build命令,输入不同平台标识,生成不同平台下的相应文件。
如下以android设备为例:
D:\hello> phonegap build android
要查看详细(verbose)执行过程,可增加命令参数-V :
D:\hello> phonegap -V build android
之后可以看到D:\hello\platforms\android里出现Android项目,这个项目可以用eclipse打开。

5、安装运行
在模拟器或移动设备上测试App: D:\hello> phonegap install android
也可用参数e专门指定运行在模拟器上:D:\hello> phonegap -e install android

6、编译并运行(相当于上面build和install两步骤操作)
D:\hello> phonegap run android
也可用参数e专门指定运行在模块器上:D:\hello> phonegap -e run android

附录:如果需要为webapp提供一些调用原生api或设备的功能,比如摄像头、电池信息、访问文件、读取通讯录等,需要为phongap项目添加phonegap插件。
添加插件的方法(确保已经安装了GitHub)
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    

下面还有几个非官方的
Barcode Scanner 二维码,支持 ios,   android
phonegap local plugin add http://github.com/wildabeast/BarcodeScanner.git

Toast 弹出消息,支持 ios,  android 和wp8
phonegap local plugin add http://github.com/EddyVerbruggen/Toast-PhoneGap-Plugin.git

选择 文件对话框,只支持a ndroid
phonegap local plugin add http://github.com/don/cordova-filechooser.git

锁定屏幕方向,支持 ios,   android
phonegap local plugin add http://github.com/yoik/cordova-yoik-screenorientation.git

通知推送,支持 ios,  android,  wp8和Amazon Fire OS (这个插件的android版使用的是GCM推送,在国内基本不能用)
phonegap local plugin add http://github.com/phonegap-build/PushPlugin.git

WebIntent 安卓“意图”插件(不懂意图是啥的去学下安卓),支持 android
phonegap local plugin add http://github.com/Initsogar/cordova-webintent#webintent-android-plugin-for-cordova-3x.git

wizUtils 比较实用的一个工具类插件,可以获取安装包的版本、获取设备宽高、设置和获取粘贴板内容、重启app,支持 ios,   android
phonegap local plugin add http://github.com/Wizcorp/phonegap-plugin-wizUtils.git

preferences 存储偏好设置的插件(用来存储你的app的设置信息),支持 ios,   android
phonegap local plugin add http://github.com/dferrell/plugins-application-preferences .git
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值