phonegap学习之CordovaWebView
来源:互联网 发布:鹏业软件官方网站 编辑:程序博客网 时间:2024/04/30 01:13
这是在app中嵌入cordova控件的学习,关于如何打包cordova-x.x.x.jar可以参照上一篇博客
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学习-执行原理
- ASP.NET的必须知道的东东(HttpModule,HttpHandler)之二
- wifi bt共存设计
- DSP 之GPIO编程
- notepad++输入中文程序就假死
- MySQL 写入中文乱码问题
- phonegap学习之CordovaWebView
- C++的类成员函数的使用体会
- 微信公共服务平台开发(.Net 的实现)3-------发送文本消息
- 机房收费系统之项目开发计划
- 面向对象第一节——面向对象思想
- 解决Eclipse无法打开“Failed to load the JNI shared library”
- 图结构练习——BFS——从起始点到目标点的最短步数
- STL 源码分析《1》---- list 归并排序的 迭代版本, 神奇的 STL list sort
- 寒假训练--图的基本知识--图结构练习——BFSDFS——判断可达性