Android中PhoneGap的使用方法

1 phonegap.js 加入到项目。
2 phonegap.jar 加入到项目,变成奶瓶
3 模仿js 下载phonegap的源码,在资产目录底下。


/*
 * PhoneGap is available under *either* the terms of the modified BSD license *or* the
 * MIT License (2008). See http://opensource.org/licenses/alphabetical for full text.
 *
 * Copyright (c) 2005-2010, Nitobi Software Inc.
 * Copyright (c) 2010-2011, IBM Corporation
 */


if (!PhoneGap.hasResource("")) {
PhoneGap.addResource("");


/**
 * This class contains information about the current network Connection.
 * @constructor
 HM是我们自己定义的类
 */
var HM = function() {
   
};






/**
 * Get connection info
 *
 * @param {Function} successCallback The function to call when the Connection data is available
 * @param {Function} errorCallback The function to call when there is an error getting the Connection data. (OPTIONAL)
 HM 这个是我们定义的类
 testLogin 是我们定义的方法
 
 option是参数
 */
HM.prototype.testLogin = function(successCallback, errorCallback ,option) {
    // Get info
    PhoneGap.exec(successCallback, errorCallback, "Network Status", "getConnectionInfo", []);
};


/**
 *hmCommen 是我们自己定义的属性
 */
PhoneGap.addConstructor(function() {
    if (typeof navigator.hmCommen === "undefined") {
    HM.hmCommen = new Object();
    }
   
});
}


4 在我们项目的入口处去继承 MainActivity extends DroidGap;
5 在res目录下面 ,需要把系统源码里面的配置文件复制过来
  phonegap.xml我们不需要管。
  plugins.xml我们需要配置
  /**
   *name 是service 配置的名字
    value 具体的类名
   */
    
  <plugin
        name="HM_service"
        value="com.example.hmphonegap.HmTest" />


========================================================
/**
   *Network Status 这个是service的名字 需要跟plugins里面的name对应起来
    getConnectionInfo 这个东西是action 具体调用哪个方法 android开发人员自己定义的类  HMTest2 extends Plugin
   */
HM.prototype.testLogin = function(successCallback, errorCallback ,option) {
    // Get info
    PhoneGap.exec(successCallback, errorCallback, "Network Status", "getConnectionInfo", []);
};
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值