I’m using the native WebPopup for some of the UI in my game (settings, integration with social networks).
In the case of settings I communicate with the Lua code via pseude-URLs and a listener as shown in the documentation. I not only use it for closing the view but also to inform the Lua based game code of some changes in the settings (e.g. tapping on “no music” immediately turns background music off, not just after the web view is closed).
This works very well on iOS, but unfortunately not on Android. The pseudo-URLs cause the browser to actually try to load them and of course fails in doing so. The web view will show an error:
Error web view on Android
[text]
Web page not available
The Web page at view:green might be temporarily down or it my have moved permanently to a new web address.
…
[/text]
This is the example code that works well on iOS, but causes the problem on Android (tested on Nexus S with Android 2.3.4).
main.lua
if system.getInfo("platformName") ~= "Android" then
display.setStatusBar(display.HiddenStatusBar)
end
local testHeight = 20
local test = display.newRect(0, 0, display.contentWidth, testHeight)
test:setFillColor(255, 255, 255, 255)
local function listener(event)
local shouldLoad = true
if string.find(event.url, "view:close") == 1 then
shouldLoad = false
elseif string.find(event.url, "view:green") == 1 then
test:setFillColor(0, 255, 0, 255)
elseif string.find(event.url, "view:red") == 1 then
test:setFillColor(255, 0, 0, 255)
end
return shouldLoad
end
local webPopupOptions = {
hasBackground = true,
baseUrl = system.ResourceDirectory,
urlRequest = listener
}
native.showWebPopup(0, testHeight, display.contentWidth, display.contentHeight, "test.html", webPopupOptions)
test.html
[html]
<meta charset="utf-8">
<title>Test</title>
<meta name="viewport" content="width=device-width; initial-scale=1.0; maximum-scale=1.0; user-scalable=0;">
# Test
- [Close](view:close)
- [Green](view:green)
- [Red](view:red)
[/html]
Is this a known problem on Android? If so when will this be fixed? Or is there any workaround for this? It would take too much work to change all my web based UI just for Android. Please give me some advice.
Thomas
[import]uid: 8460 topic_id: 12020 reply_id: 312020[/import]