Webview shouldOverrideUrlLoading not getting called

前端 未结 4 1967
难免孤独
难免孤独 2021-01-02 15:30

I am making an ebook reader which uses epub format to load books into webviews. In some of the books there is an anchor link to some portions in the same chapter. Each chapt

4条回答
  •  谎友^
    谎友^ (楼主)
    2021-01-02 16:14

    I haven't tested this programmatically but I believe you are facing this issue because there was major changes in how webview works post OS 4.4 . You should check this link https://developer.android.com/guide/webapps/migrating.html#URLs

    Under section 'Custom Url Handling' it says that shouldOverrideUrlLoading() will not be invoked for invalid url. Ideally file:// should be treated as valid url but seems like it's not happening here.

    One possible solution is to load you main webview content with loadDataWithBaseURL and provide baseurl as some test url e.g. http://mytestap.testurl , it will guarantee shouldOverrideUrlLoading will get invoked all time. As a next step you need to remove prefix 'http://mytestap.testurl' if exist in the received url in shouldOverrideUrlLoading callback.

提交回复
热议问题