phonegap学习之CordovaWebView
来源:互联网 发布:江苏移动网络测速 编辑:程序博客网 时间:2024/05/16 06:08
最近学习phonegap,发现网上的中文文章都太旧了,现在选择最新的phonegap-2.9.1的学习过程记录下来,一方面整理过,能够加深理解,另一方面也可以帮助其他人学习,首先可以到phonegap官网下载phonegap-2.9.1
这是关于如何在app中嵌入cordova控件的学习,关于如何打包cordova-x.x.x.jar可以到官网下载phonegap2.9.1,在其中的\lib\android中根据README.md的提示打包即可。
1、把打包好的jar包导入android工程的libs目录下
2、在布局文件中的加入cordovawebview控件
<org.apache.cordova.CordovaWebView
android:id="@+id/tutorialView"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
3、相关Activity必须改造为实现接口CordovaInterface,相关使用可参照/framework/src/org/apache/cordova/CordovaActivity.java,简要代码如下:
publicclassCordovaViewTestActivityextendsActivityimplementsCordovaInterface{
4、app需要调用摄像头可以采用如下代码:
CordovaWebView cwv;
/* Called when the activity is first created. */
@Override
publicvoid onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
cwv =(CordovaWebView) findViewById(R.id.tutorialView);
Config.init(this);
cwv.loadUrl(Config.getStartUrl());
}
@Override
publicvoid setActivityResultCallback(CordovaPlugin plugin){
this.activityResultCallback = plugin;
}
/**
* Launch an activity for which you would like a result when it finished. When this activity exits,
* your onActivityResult() method is called.
*
* @param command The command object
* @param intent The intent to start
* @param requestCode The request code that is passed to callback to identify the activity
*/
publicvoid startActivityForResult(CordovaPlugin command,Intent intent,int requestCode){
this.activityResultCallback = command;
this.activityResultKeepRunning =this.keepRunning;
// If multitasking turned on, then disable it for activities that return results
if(command !=null){
this.keepRunning =false;
}
// Start activity
super.startActivityForResult(intent, requestCode);
}
@Override
/**
* Called when an activity you launched exits, giving you the requestCode you started it with,
* the resultCode it returned, and any additional data from it.
*
* @param requestCode The request code originally supplied to startActivityForResult(),
* allowing you to identify who this result came from.
* @param resultCode The integer result code returned by the child activity through its setResult().
* @param data An Intent, which can return result data to the caller (various data can be attached to Intent "extras").
*/
protectedvoid onActivityResult(int requestCode,int resultCode,Intent intent){
super.onActivityResult(requestCode, resultCode, intent);
CordovaPlugin callback =this.activityResultCallback;
if(callback !=null){
callback.onActivityResult(requestCode, resultCode, intent);
}
}
5、记得要增加线程池,plugin需要跑在线程中:
@Override
复制
publice ExecutorService getThreadPool(){
return threadPool;
}
6、复制app的HTML 和JavaScript files 到 the Android 工程的/assets/www
目录下。
7、从/framework/res/xml
config.xml
文件到工程的/res/xml
directory
0 0
- phonegap学习之CordovaWebView
- phonegap学习之CordovaWebView
- PhoneGap使用CordovaWebView时注意事项
- Fragment里使用 PhoneGap 的 CordovaWebView
- 如何在Fragment中使用phonegap的CordovaWebView
- 如何在Fragment中使用phonegap的CordovaWebView
- 在PhoneGap应用中拦截CordovaWebView的url
- phonegap使用的初步研究(一)cordovaWebView不能加载外网的页面
- phoneGap+android学习之搭建环境
- phonegap学习进度之项目名称
- PhoneGap学习
- PhoneGap之学习之一:开发环境的搭建
- PhoneGap学习笔记-----phone3.4之Android搭建
- Sencha Touch+Phonegap 开发学习笔记之List相关
- phonegap学习之二:创建项目和添加平台
- PhoneGap学习笔记一:PhoneGap简介
- phonegap 学习笔记-安装phonegap
- PhoneGap学习-执行原理
- nodejs安装
- Android基础-3(Fragment)
- Web.xml中的url-pattern详解
- 1059. Prime Factors (25)
- TP上传文件的自定义名称
- phonegap学习之CordovaWebView
- Java 变量初始化
- 浏览器工作原理之浏览器结构
- ActiveMQ REST Management API
- Oracle外连接与条件的组合
- DataGridViewCheckBoxColumn小结
- 和老BIOS说永别 EFI BIOS技术解析
- 两种类型的web框架: 基于请求的和基于组件的
- Hibernate第二讲:Hibernate核心API和Hibernate开发步骤