Jump to content

[TOPIC: topicViewTemplate]
[GLOBAL: userSmallPhoto]
Photo

Pass parameters to active webview
Started by alg Jan 11 2019 06:05 AM

- - - - -
4 replies to this topic
webview interaction javascript lua
[TOPIC CONTROLS]
This topic has been archived. This means that you cannot reply to this topic.
[/TOPIC CONTROLS]
[modOptionsDropdown]
[/modOptionsDropdown]
[reputationFilter]
[TOPIC: post.html]
#1

alg

[GLOBAL: userInfoPane.html]
alg
  • Observer

  • 25 posts
  • Corona SDK

I have an app that in part, uses a webview to display an existing web application.  I can pass parameters into the webview via parameters in the url.  My application receives notifications from onesignal which i receive through a notification callback.  That callback determines when to goto the webview scene and what parameters to pass:

function gotoMainScene(message, additionalData, isActive)
  local message = message or ""
  -- build a baseline params object
  local params={
    base=pwaUrl,
    devId=osw:myDevId(),
    message=message or nil,
    isActive=isActive or nil,
    appVersionString = system.getInfo('appVersionString'),
    platformName = system.getInfo("platform"),
    platformVersion = system.getInfo("platformVersion"),
    modelName = system.getInfo("model"),
    archInfo = system.getInfo("architectureInfo"),
  }

  -- flatten additional data and add to params
  if additionalData ~= nil then
    for k,v in pairs(additionalData) do
      params[k]=v
    end
  end

  -- goto the webview
  composer.gotoScene('scene_webview',
    {
      effect="fade",
      time=100,
      params=params,
    }
  )
end

The problem with this approach is that it reloads the webview whenever a notification occurs.  Is there a way to pass parameters to the webview in the background?



[TOPIC: post.html]
#2

Rob Miracle

[GLOBAL: userInfoPane.html]
Rob Miracle
  • Moderator

  • 25,896 posts
  • Enterprise

Unfortunately, there are not any means beyond what you're already doing to pass data from Corona/Lua to the webView.

 

Rob



[TOPIC: post.html]
#3

sanctempdyra

[GLOBAL: userInfoPane.html]
sanctempdyra
  • Observer

  • 5 posts
  • Corona SDK

Correct me if I am wrong.

 

16
 
I would add that the load of the javascript function should be done when the html is loaded. To control that, you can use the following:
 
webview.getSettings().setJavaScriptEnabled(true);
webview.loadUrl("file:///android_asset/test.html");
webview.setWebViewClient(new WebViewClient(){
    public void onPageFinished(WebView view, String url){   
        webview.loadUrl("javascript:init('" + theArgumentYouWantToPass + "')");
    }           
});


[TOPIC: post.html]
#4

Rob Miracle

[GLOBAL: userInfoPane.html]
Rob Miracle
  • Moderator

  • 25,896 posts
  • Enterprise

@sanctempdyra, if he wants to go with Corona Native, that might work for native Android builds. Corona uses Lua, not Java.

 

Using native builds instead of simulator builds would give you full access to the webView on the various platforms.

 

Rob



[TOPIC: post.html]
#5

alg

[GLOBAL: userInfoPane.html]
alg
  • Observer

  • 25 posts
  • Corona SDK

Thanks Rob and @sanctempdyra.  For this release, I've elected to use polling while the app is active and only pass parameters through the URL when the app is not active.




[topic_controls]
[/topic_controls]