Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Mobile and Embedded
  4. WebView load files on Android 11 API 30
Forum Updated to NodeBB v4.3 + New Features

WebView load files on Android 11 API 30

Scheduled Pinned Locked Moved Unsolved Mobile and Embedded
4 Posts 1 Posters 700 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    Marek
    wrote on last edited by Marek
    #1

    Hi
    I have an application which uses QWebSocketServer to change some elements on webpage that I'm displaying from local storage in WebView - on Android

        server = 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

    M 1 Reply Last reply
    0
    • M Marek

      Hi
      I have an application which uses QWebSocketServer to change some elements on webpage that I'm displaying from local storage in WebView - on Android

          server = 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

      M Offline
      M Offline
      Marek
      wrote on last edited by
      #2

      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

      M 1 Reply Last reply
      0
      • M 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

        M Offline
        M Offline
        Marek
        wrote on last edited by
        #3

        So this is related to this bug
        https://bugreports.qt.io/browse/QTBUG-97487

        Maybe someone has a workaround ?
        Like using Android JNI to set setAllowFileAccess(true) in WebView settings ? ;)

        Best Regards
        Marek

        M 1 Reply Last reply
        0
        • M Marek

          So this is related to this bug
          https://bugreports.qt.io/browse/QTBUG-97487

          Maybe someone has a workaround ?
          Like using Android JNI to set setAllowFileAccess(true) in WebView settings ? ;)

          Best Regards
          Marek

          M Offline
          M Offline
          Marek
          wrote on last edited by
          #4

          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

          1 Reply Last reply
          0

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved