phonegap学习之CordovaWebView
2014-02-19 21:01
225 查看
这是在app中嵌入cordova控件的学习,关于如何打包cordova-x.x.x.jar可以参照上一篇博客
1、把打包好的jar包导入android工程的libs目录下
2、在布局文件中的加入如下cordovawebview控件
3、相关Activity必须改造为实现接口CordovaInterface,相关使用可参照/framework/src/org/apache/cordova/CordovaActivity.java,简要代码如下:
[/code]
[/code]
5、记得要增加线程池,plugin需要跑在线程中:
[/code]
7、从
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,简要代码如下:
[/code]
publicclassCordovaViewTestActivityextendsActivityimplementsCordovaInterface{ 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()); }4、app需要调用摄像头可以采用如下代码:
[/code]
@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需要跑在线程中:
[/code]
@Override
publice ExecutorService getThreadPool(){
return threadPool;
}
6、复制app的HTML 和JavaScript files 到 the Android 工程的 /assets/www
目录下。7、从
/framework/res/xml复制
config.xml文件到工程的
/res/xmldirectory[/code]
相关文章推荐
- phonegap学习之CordovaWebView
- [Cordova/Phonegap] 改进InAppBrowser插件(WebView),让其<input type="file">支持选择文件
- 如何在Fragment中使用phonegap的CordovaWebView
- PhoneGap使用CordovaWebView时注意事项
- 如何在Fragment中使用phonegap的CordovaWebView
- [Phonegap+Sencha Touch] 移动开发70 cordova app中使用增强的webview
- Fragment里使用 PhoneGap 的 CordovaWebView
- 在PhoneGap应用中拦截CordovaWebView的url
- phonegap使用的初步研究(一)cordovaWebView不能加载外网的页面
- Android学习之WebView文档翻译
- 混合开发 Hybird Cordova PhoneGap Ionic web JS 跨平台
- IOS开源项目Coding学习笔记(4):SVWebViewController: 服务条款界面
- [WebView学习之二]:使用Web Apps 支持不同分辨率屏
- ionic 安装cordova-plugin-crosswalk-webview,报Could not resolve all dependencies for configuration ':_ar
- WebView全面学习(二)-- Native与js双方通信
- Ionic安装cordova-plugin-crosswalk-webview报错
- WebView组件学习以及WebViewClient 的方法解释
- cordova--入门 webview_url修改,打开web时跳出app
- android 4.4 webview 学习
- WebViewJavascriptBridge学习