Java – disable WebView links to run on emulators, but not on devices
I want to disable links to the pages I load into WebView objects My code runs perfectly on my simulator using API 25, but there is no 23 API on my phone
This is the code that blocks my WebView link:
public class NoLinksWebViewClient extends WebViewClient { @Override public boolean shouldOverrideUrlLoading(WebView view,WebResourceRequest request) { return true; } }
I set my webviewclient as an object of type nolinkswebviewclient It can be implemented on the simulator, but not on my real mobile phone
How to solve this?
Solution
I think the key difference is not between simulators and devices, but different API levels If you view documents on the webviewclient, you will notice that there are two similar but different methods:
// since API 24 boolean shouldOverrideUrlLoading(WebView view,WebResourceRequest request) // before API 24,Now deprecated boolean shouldOverrideUrlLoading(WebView view,String url)
Since you only overwrite the newer methods, the default logic works on the old device This happens because obviously the API 23 device cannot know that the method will be replaced with a different method in API 24, so it will still call the old (now deprecated) method
I believe you should cover these two methods to solve this problem