Catch "page finished loading" event and do something in ionic/cordova MainActivity.java with xwalk webview

2.1k Views Asked by At

I have a android app that has built using ionic and i have used xwalk web-view in it. I need to catch page finished loading event inside my MainActivity.java which extends the CordovaActivity class and then perform some action. How i can do this.

3

There are 3 best solutions below

0
On

the process event quite similar to Android Webview try this

xWalkView.setResourceClient(new XWalkResourceClient(xWalkView) {
     @Override
      public void onLoadFinished(XWalkView view, String url) {
           super.onLoadFinished(view, url);
           // Stop your loading dialog here
      }
 });

take care

1
On

If you are using android WebView, please check out the onPageFinished() method.

http://developer.android.com/reference/android/webkit/WebViewClient.html#onPageFinished(android.webkit.WebView, java.lang.String)

1
On

If you are using xwalkview in Crosswalk Embedded Mode, its API XWalkResourceClient#onLoadFinished can be useful to you. The detail is here API_docs, you can use like this:

class ResourceClient extends XWalkResourceClient {

    public ResourceClient(XWalkView xwalkView) {
        super(xwalkView);
    }

    public void onLoadStarted(XWalkView view, String url) {
        super.onLoadStarted(view, url);
        Log.d(TAG, "Load Started:" + url);
    }

    public void onLoadFinished(XWalkView view, String url) {
        super.onLoadFinished(view, url);
        Log.d(TAG, "Load Finished:" + url);
    }

    public void onProgressChanged(XWalkView view, int progressInPercent) {
        super.onProgressChanged(view, progressInPercent);
        Log.d(TAG, "Loading Progress:" + progressInPercent);
    }
}

mXWalkView.setResourceClient(new ResourceClient(mXWalkView));
mXWalkView.load("http://www.google.com/", null);