phonegap-2.0+android教程
2014-05-04 20:59
330 查看
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" onclick="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
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" onclick="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
相关文章推荐
- Android版添加phonegap--支付宝2.0快捷支付插件教程
- Android版添加phonegap--imagePicker插件教程
- Android添加phonegap--sencha touch2插件教程
- android+phonegap 开发环境教程
- Android版添加phonegap--发短信插件教程
- Android版添加phonegap--微信授权插件教程
- Eclipse+android+jdk+phonegap 开发环境教程
- Android教程2.0:四大主干类的介绍
- Android版添加phonegap--员工簿插件教程
- Android版添加phonegap--websocket客户端插件教程
- Android版添加phonegap--Crosswalk插件教程
- Android版添加phonegap--sencha打包插件教程
- Android Retrofit 2.0(二)使用教程OkHttp3 + Gson + RxJava
- Android版添加phonegap-百度地图插件教程
- Android版添加phonegap-银联支付插件教程
- Android版添加phonegap---横竖屏锁定插件教程
- 教程:如何为Android写一个PhoneGap插件
- Android版添加phonegap--InAndroid视频播放功能插件教程
- Android版添加phonegap--融云即时通讯插件教程
- Android版添加phonegap-读取手机短信插件教程