Context
To many, this situation might appear to be repetitive. However, I assure you that it is not.
My objective is to import html data into a WebView
, while being able to intercept user hyperlink requests. During this process, I came across this helpful answer which fulfills my requirements, except for capturing requests for items like CSS files and images:
// Notify the webclient when a url is about to load
@Override
public boolean shouldOverrideUrlLoading(WebView view, WebResourceRequest request){
return true;
}
// Perform an action when the desired URL is ready to load
@Override
public void onLoadResource(WebView view, String url){
if( url.equals("http://cnn.com") ){
// Customize behavior accordingly
}
}
I have disabled automatic image loading, network loads, and execution of Javascript:
settings.setBlockNetworkLoads(true);
settings.setBlockNetworkImage(true);
settings.setJavaScriptEnabled(false);
However, these adjustments do not prevent the capture of the mentioned requests.
Perhaps there is an alternate approach to intercepting link clicks, but the only options seem to be either this method or halting external resource loading altogether.
Query
Is there a way to stop WebView
from capturing (or trying to load) resource requests such as CSS, JS, or images?
If preventing capture or loading is not possible, how can I distinguish between clicked links and web resources?
Thank you in advance!