首页 文章

当从Cordova android app更改页面时,无法获取当前Webview HTML页面路径

提问于
浏览
2

我正在尝试从cordova android应用程序中的“asset”文件夹中获取当前的html页面路径,当我们更改cordova webview中的页面时 .

我只使用MainActivity

public class MainActivity extends CordovaActivity {

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

我搜索并尝试了我最好的水平找到解决方案 . 但是现在我仍然无法找到正确的解决方案 . 我完全糊涂了,请建议以下任何解决方案,

  • 任何可用于在页面更改时检测cordova webview URL的函数,如 public boolean shouldOverrideUrlLoading(WebView view, String url) { } 方法?

  • 我们可以为Cordova Webview创建WebViewClient吗?

1 回答

  • 3

    你可以获得当前的网址

    appView.getUrl();
    

    要获取网址更改,您可以使用此方法:

    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;
    
        }
    });
    

相关问题