This is tricky. You basically need to create a new class during runtime that overrides shouldInterceptRequest:
public class SuperDuperUniqueNameForMyWebViewClient extends android.webkit.WebViewClient {
// constructor etc...
@Override
public android.webkit.WebResourceResponse shouldInterceptRequest(android.webkit.WebView view, android.webkit.WebResourceRequest request) {
// implement your logic here
}
}
To create the class dynamically, you muste compile the code on-the-fly in Java:
String source = ...;
int result = com.sun.tools.javac.Main.compile(new String[]{source}); // parameter is an array
Which in Qt C++ gives us this:
QString source = ...; // Here you need to provide the Java code for your class
QAndroidJniObject sourceObject = QAndroidJniObject::fromString(source);
jobjectArray sourceObjectArray = sourceObject.object<jobjectArray>(); // this is probably not correct
jint result = QAndroidJniObject::callStaticMethod<jint>("com/sun/tools/javac/Main",
"compile"
"([Ljava/lang/String;)I",
jobjectArray);
After that you should be able create a web view client with your own class and use it:
QAndroidJniObject myWebViewClient{"SuperDuperUniqueNameForMyWebViewClient"};
Take all of this with a grain of salt, as it is from the top of my head and I haven't tested it. At the very least it should push you in the right direction, though.