Using Crosswalk ‘Webview’ in Android Application
Ok, here is the thing, Crosswalk helps to bring down most of the comparability issues using different webviews. its based on chromium and is much stable to use with Cordova / PhoneGap apps. Some of the advantages using crosswalk are,
- Get consistent, predictable behavior by reducing Android device fragmentation.
- Use the latest web innovations and APIs. Provide a feature rich experience on all Android 4.0+ devices.
- Easily debug with Chrome DevTools.
- Improve the performance of your HTML, CSS, and JavaScript.
END OF STORY
NOW, what we are going to do is to import a compiled Crosswalk library into our android project and use it instead of traditional android webview.
Ok what we need to do is,
- download the webview from,
https://crosswalk-project.org/documentation/downloads.html [Android webview (ARM)] - Then read the following link to know how to import em to ADT
https://crosswalk-project.org/documentation/embedding_crosswalk.html
Ok, most of the instructions in these links are pretty clear, so i am not going ahead and write another on my own.
Instead i will share some useful XWalkView methods, Events and callbacks,
Load
1 |
mXWalkWebView.load("http://bincoder.com/", null); |
loads a page or content or app with the base url supplied.
void |
load(java.lang.String url, java.lang.String content)
Load a web page/app from a given base URL or a content.
|
void |
loadAppFromManifest(java.lang.String url, java.lang.String content)
Load a web app from a given manifest.json file.
|
Basic Navigation
- Forward
1 |
mXWalkWebView.getNavigationHistory().navigate(Direction.FORWARD, 1); |
- Back
1 |
mXWalkWebView.getNavigationHistory().navigate(Direction.BACKWARD, 1); |
- Reload
1 |
mXWalkWebView.reload(); |
- Stop
1 |
mXWalkWebView.stopLoading(); |
Basic Event Interception
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
mXWalkWebView.setResourceClient(new XWalkResourceClient(mXWalkWebView){ @Override public void onLoadStarted(XWalkView view, String url) { // TODO Auto-generated method stub super.onLoadStarted(view, url); } @Override public boolean shouldOverrideUrlLoading(XWalkView view, String url) { // TODO Auto-generated method stub return super.shouldOverrideUrlLoading(view, url); } @Override public void onDocumentLoadedInFrame(XWalkView view, long frameId) { // TODO Auto-generated method stub super.onDocumentLoadedInFrame(view, frameId); } @Override public void onProgressChanged(XWalkView view, int progressInPercent) { // TODO Auto-generated method stub super.onProgressChanged(view, progressInPercent); } @Override public void onLoadFinished(XWalkView view, String url) { // TODO Auto-generated method stub super.onLoadFinished(view, url); } @Override public void onReceivedClientCertRequest(XWalkView view, ClientCertRequest handler) { // TODO Auto-generated method stub super.onReceivedClientCertRequest(view, handler); } @Override public void onReceivedLoadError(XWalkView view, int errorCode, String description, String failingUrl) { // TODO Auto-generated method stub super.onReceivedLoadError(view, errorCode, description, failingUrl); } @Override public void onReceivedSslError(XWalkView view, ValueCallback<Boolean> callback, SslError error) { // TODO Auto-generated method stub super.onReceivedSslError(view, callback, error); } }); |
Will Update as i go on
Thankyou…