Android Question html5 in daydream webview

eps

Expert
Licensed User
Longtime User
I was going to say no as I felt that Daydreams were a system function and mostly non-interactive, but in the Daydream / Dreamservice tutorial it mentions 'The webview example is an interactive dream that loads the URL that the user enters with WebView' so seeing as HTML5 uses a web view or web view extras I don't see why not. I guess the only way to find out is to give it a go...! If you substitute the web view for web view extras does it work?
 
Upvote 0

Erdei Andrei Csaba

Member
Licensed User
In simple HTML5 app wrapper my html5 app is working ok

I have tried with both webviewextras and webviewextras2 library in the daydream tutorial

B4X:
Sub dd_SizeChanged
    Dim WebView1 As WebView
    Dim WebViewExtras1 As WebViewExtras
    Dim WebViewSettings1 As WebViewSettings
    WebView1.Initialize("WebView1")
    WebViewExtras1.Initialize(WebView1)
    Dim WebChromeClient1 As DefaultWebChromeClient
    WebChromeClient1.Initialize("WebChromeClient1")
    WebViewExtras1.SetWebChromeClient(WebChromeClient1)
    WebViewSettings1.setAllowFileAccess(WebView1,True)
    WebViewSettings1.setAppCacheEnabled(WebView1,True)
    WebViewSettings1.setDOMStorageEnabled(WebView1,True)
    dd.Panel.AddView(WebView1, 0dip, 50dip, dd.Panel.Width, dd.Panel.Height)
    WebView1.LoadUrl("file:///android_asset/index.html")
End Sub
with webviewextras2 library - no errors but blank screen


B4X:
Sub dd_SizeChanged
    Dim WebView1 As WebView
    Dim WebViewExtras1 As WebViewExtras
    Dim WebViewSettings1 As WebViewSettings
    WebView1.Initialize("WebView1")
    WebViewExtras1.addWebChromeClient(WebView1, "WebViewExtras1")
    WebViewSettings1.setAllowFileAccess(WebView1,True)
    WebViewSettings1.setAppCacheEnabled(WebView1,True)
    WebViewSettings1.setDOMStorageEnabled(WebView1,True)
    dd.Panel.AddView(WebView1, 0dip, 50dip, dd.Panel.Width, dd.Panel.Height)   
    WebView1.LoadUrl("file:///android_asset/index.html")   
End Sub
with webviewextras - a bunch of errors like
B4X:
Access to Image at 'file:///android_asset/html5game/particles/IDR_GIF2.png' from origin 'null' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'null' is therefore not allowed access. in file:///android_asset/index.html (Line: 0)
[.Offscreen-For-WebGL-0xb80b62e0]RENDER WARNING: texture bound to texture unit 0 is not renderable. It maybe non-power-of-2 and have incompatible texture filtering. in file:///android_asset/index.html (Line: 0)

I have the <No 'Access-Control-Allow-Origin'> header in my index.html
 
Upvote 0

Erdei Andrei Csaba

Member
Licensed User
It is working.

B4X:
Sub dd_SizeChanged
    Dim WebView1 As WebView
    Dim WebViewExtras1 As WebViewExtras
    lastUrl = "file:///android_asset/index.html"
    WebView1.Initialize("WebView1")
    WebView1.JavaScriptEnabled=True
    WebViewExtras1.addWebChromeClient(WebView1, "WebViewExtras1")
    Dim jo As JavaObject = WebView1
    Dim settings As JavaObject = jo.RunMethod("getSettings", Null)
    Dim r As Reflector
    r.Target = settings
    r.RunMethod2("setAllowUniversalAccessFromFileURLs", True, "java.lang.boolean")
    dd.Panel.AddView(WebView1, 0dip, 0dip, dd.Panel.Width, dd.Panel.Height)
    WebView1.LoadUrl(lastUrl)
End Sub

It was needed to have setAllowUniversalAccessFromFileURLs set to true.
 
Upvote 0

eps

Expert
Licensed User
Longtime User
Great, so it's working as you need it to?

To be honest I didn't know 'Daydreams' even existed on Android!
 
Upvote 0
Top