phonegap学习之CordovaWebView
2014-02-11 16:58
211 查看
最近学习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控件
3、相关Activity必须改造为实现接口CordovaInterface,相关使用可参照/framework/src/org/apache/cordova/CordovaActivity.java,简要代码如下:
[/code]
[/code]
5、记得要增加线程池,plugin需要跑在线程中:
[/code]
7、从
这是关于如何在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,简要代码如下:
[/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
- 如何在Fragment中使用phonegap的CordovaWebView
- 如何在Fragment中使用phonegap的CordovaWebView
- PhoneGap使用CordovaWebView时注意事项
- [Phonegap+Sencha Touch] 移动开发70 cordova app中使用增强的webview
- Fragment里使用 PhoneGap 的 CordovaWebView
- 在PhoneGap应用中拦截CordovaWebView的url
- phonegap使用的初步研究(一)cordovaWebView不能加载外网的页面
- [Cordova/Phonegap] 改进InAppBrowser插件(WebView),让其<input type="file">支持选择文件
- android清除WebView使用的缓存的学习记录
- Android开发学习笔记:WebView的使用
- 《第一行代码》第二版 学习总结23 WebView的基本使用
- android webview 学习
- Android中监听Phonegap的webview的start,finish等事件
- iOS学习之WebView的使用
- android phonegap CordovaView 调整字体大小(仿微信)
- [Android学习系列21]webview的一些事
- Android学习之 WebView使用小结
- WebView项目中PhoneGap插件使用细节 转
- 移动web相关学习(一)——WebView的学习(1)