Android Question Not allowed to load local resource

dbalman

Member
Licensed User
Longtime User
Hi, I have a WebView app that has worked fine on all versions of Android from 4.3 on down, but one particular URL gives me this error on Android 4.4.x KitKat. Here's a sample project to demonstrate:

B4X:
Sub Process_Globals
   
End Sub

Sub Globals
    Dim WebViewExtras1 As WebViewExtras
End Sub

Sub Activity_Create(FirstTime As Boolean)
   
    Dim WebView1 As WebView
    WebView1.Initialize("")
    WebViewExtras1.Initialize(WebView1)

    Dim JavascriptInterface1 As DefaultJavascriptInterface
    JavascriptInterface1.Initialize
    WebViewExtras1.AddJavascriptInterface(JavascriptInterface1, "B4A")

    Dim WebChromeClient1 As DefaultWebChromeClient
    WebChromeClient1.Initialize("WebChromeClient1")

    WebViewExtras1.SetWebChromeClient(WebChromeClient1)

    Activity.AddView(WebViewExtras1, 0, 0, 100%x, 100%y)
       
    WebViewExtras1.LoadUrl("https://portal.unisys.com/portal/page/portal/ESERVICE_PGR/global/SERVICE_CONSOLE_LOGIN/SERVICE_CONSOLE_PDA_PGE")

End Sub

And here's the output from the log:

B4X:
** Activity (main) Pause, UserClosed = true **
** Activity (main) Resume **
Timeline: Activity_idle id: android.os.BinderProxy@422b62e0 time:54171314
(Intent) Intent { act=android.intent.action.MAIN flg=0x20000000 cmp=b4a.example/.main }
no extras
Timeline: Activity_launch_request id:b4a.example time:54172221
** Activity (main) Pause, UserClosed = false **
** Activity (main) Create, isFirst = true **
** Activity (main) Resume **
Not allowed to load local resource: file:///android_asset/webkit/android-weberror.png in data:text/html,chromewebdata (Line: 12)

I am using Martin Pearman's WebViewExtras2 library, but I'm not sure which version. As a side note, this same URL will fail in the default android browser as well as in Chrome with a Connection Problem: net::ERR_FAILED, but works in the beta version of Chrome and with Firefox.

I have seen a few discussions on the internet regarding this error and the general consensus seems to be use loadDataWithBaseURL to bypass the problem. However, I've tried this by using the reflection library without success.

B4X:
    Dim r As Reflector
    r.Target = WebViewExtras1
    r.RunMethod4("loadDataWithBaseURL", Array As Object ("file:///android_asset/", _
        "<!DOCTYPE html><html><body><script>{location.href='https://portal.unisys.com/portal/page/portal/ESERVICE_PGR/global/SERVICE_CONSOLE_LOGIN/SERVICE_CONSOLE_PDA_PGE';}</script></body></html>", _
        Null, "UTF-8", Null), Array As String("java.lang.String", "java.lang.String", "java.lang.String", "java.lang.String", "java.lang.String"))

Thanks for any help anyone can provide. I am tearing my hair out here.

Dan
 

dbalman

Member
Licensed User
Longtime User
Thanks for the quick response Erel, but there are no files to move. The code can be stripped to just a webview loading this particular URL, and it still will not work on KitKat. Do you mean I need to move the apk? Here is a link that describes the issue in more detail.
 
Upvote 0

dbalman

Member
Licensed User
Longtime User
Well, if anyone figures out how some people are managing to bypass this error, please let me know.
 
Upvote 0
Top