Dinesh Kumar
Dinesh Kumar

Reputation: 43

Cannot get Current Webview HTML page path when page changed from Cordova android app

I am trying to get current html page path from "asset" folder in cordova android app, when we changing the pages inside the cordova webview.

I am using only MainActivity

public class MainActivity extends CordovaActivity {

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    loadUrl(launchUrl);
}}

I searched and tried my level best to find the solution. But still now I cannot get the right solution. I am totally confused, Please suggest any solution for the followings,

  1. Any function available to detect cordova webview URL when page changed like public boolean shouldOverrideUrlLoading(WebView view, String url) { } method?
  2. Can we create WebViewClient for Cordova Webview?

Upvotes: 2

Views: 1534

Answers (1)

jcesarmobile
jcesarmobile

Reputation: 53301

You can get the current url with

appView.getUrl();

To get url changes you can use this:

SystemWebView wv = (SystemWebView)appView.getView();
wv.setWebViewClient(new SystemWebViewClient((SystemWebViewEngine)appView.getEngine()){
    public boolean shouldOverrideUrlLoading(WebView view, String url) {

        // you can get the current url with view.getUrl()
        // or the url that it's trying to load next with url
        return false;

    }
});

Upvotes: 3

Related Questions