Pass parameters to active webview

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?

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

Rob

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 + “’)”);

    }           

});

@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

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.

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

Rob

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 + “’)”);

    }           

});

@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

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.