phonegap-2.0+android教程

phonegap-2.0的安卓目录结构


1.创建新安卓项目

2.创建目录

  • /libs
  • assets/www/js

3.分别拷贝cordova-2.0.0.jar和cordova-2.0.0.js到libs(build-path) 和 www/js下

4.将xml整个文件夹拷打res目录下

5.AndroidManifest.xml 完全参考example里面的写法 

6. 创建Activity和plugins类

package com.lilin.myphonegap;

import org.apache.cordova.DroidGap;

import android.app.Activity;
import android.os.Bundle;


public class MyphonegapActivity extends DroidGap {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        
        
        super.loadUrl("file:///android_asset/www/index.html");
        
        
    }
}



package com.lilin.myphonegap.plugins;


import org.apache.cordova.api.Plugin;
import org.apache.cordova.api.PluginResult;
import org.json.JSONArray;
import org.json.JSONObject;


public class MyTestPlugins extends Plugin{


@Override
public PluginResult execute(String action, JSONArray args, String callbackId) {
//JSONObject arg = args.optJSONObject(0)
System.out.println("OK>>>>>>>>>>>>>>");;
System.out.println( action+">>" );
if("lilin_test".equalsIgnoreCase(action)){
return doTest();
}
return null;
}

private PluginResult doTest() {
PluginResult resutl = new PluginResult(PluginResult.Status.OK);
System.out.println( "OK222");
return resutl;
}


}


7.在xml的config.xml添加

<plugin name="lilin_test_service" value="com.lilin.myphonegap.plugins.MyTestPlugins"/>

8.在www的文件夹下创建index.html

<!DOCTYPE HTML>
<html>
<head>
<title>Cordova</title>
<script type="text/javascript" charset="utf-8" src="js/cordova-2.0.0.js"></script> 
<script type="text/javascript">


function testbtn(){
 
cordova.exec(successCallback,errorCallback,"lilin_test_service","lilin_test",[]);
};
function alertDismissed() {
    // do something
}
function successCallback(arg){
//alert("successCallback ok");
//alert(arg.recode+" : "+arg.msg);
navigator.notification.alert(
   'successCallback ok!',  // message
   alertDismissed,         // callback
   'Game Over',            // title
   'Done'                  // buttonName
);
};


function errorCallback(msg){
alert(msg);

};
</script>
</head>
<body>
<input type="button" οnclick="testbtn()" value="testbtn"></input>
</body>
</html>


9.项目预览



参考文章  http://docs.phonegap.com/en/2.0.0rc1/guide_getting-started_android_index.md.html#Getting%20Started%20with%20Android


jar下载地址 https://github.com/phonegap/phonegap/zipball/2.0.0



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值