WebView load files on Android 11 API 30
-
Hi
I have an application which uses QWebSocketServer to change some elements on webpage that I'm displaying from local storage in WebView - on Androidserver = new QWebSocketServer( QStringLiteral("WebView Listener"), QWebSocketServer::NonSecureMode ); if (!server->listen(QHostAddress::LocalHost, 55222)) { qDebug()<< "Server didn't run! "; return; }
And on webside in js scripts, saved in assets (not local directory)
window.onload = function() { var socket = new WebSocket("ws://127.0.0.1:55222"); socket.onopen = function() { new QWebChannel(socket, function(channel) { alert('agreementscripter channel opened'); backend = channel.objects.WebViewManager; agreemenModel = channel.objects.AgreementModel;
Works fine with API 29. When changing to api 30, it looks like JS file is not loaded, because there is no message from JS on socket.onopen or socket.onerror
Has someone idea what might be the problem ?Best Regards
Marek -
I have moved JS script from mobile application to server on the internet, so it is downloaded from external link and now it works.
However it looks like WebView does not load anything from local application directory, like:<img id="img2_1" src="img2_1.png" alt="sign2" width="300px" />
and image is not loaded
-
Hi all
I would like to change this settings - setAllowFileAccess(true) via java code.
I can call static functions with AndroidJNI, I have created small class for that, but the problem is that I don't know ID of the WebView. In every example I see they use findViewById and it looks like this is ID from XML file describing layout.
Anyone knows what can be the ID of WebView initialized by Qt ?
Or can this be done otherwise ?import org.qtproject.qt5.android.bindings.QtApplication; import org.qtproject.qt5.android.bindings.QtActivity; import android.content.Intent; import android.app.Activity; import android.os.Bundle; import android.webkit.WebSettings; import android.webkit.WebView; import android.webkit.WebViewClient; import android.os.Bundle; import java.io.File; import android.net.Uri; public class WebViewSettings extends QtActivity { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); } public static boolean updateSettings(String dummy) { WebView webView = (WebView) findViewById(R.id.webview); WebSettings webSettings = webview.getSettings(); webSettings.setAllowFileAccess(true); return true; } }
https://stackoverflow.com/questions/70412798/webview-setallowfileaccess-from-qt-application
Best Regards
Marek