working on a native Android app. I am able to load a local file index.html into a WebView: The web url loads fine. Now, I would like to load the web with some parameters, in the same way one types this in the browser: So I can get those values inside the javascript of the html file. Is there any way to send parameters to a local html file?
html:
<input type="hidden" name="deviceid" id="deviceid"/>
i pass the device_id on local html file.
You can send them as get parameters while loading your html in WebView itself, and then later catch it in your JavaScript using window.location.href
property. Something like this:
WebView myWebView = (WebView) findViewById(R.id.webview);
myWebView.loadUrl("/assets/index.html?foo=bar");
edit
To send the Device-ID, use the below code instead:
TelephonyManager tm=(TelephonyManager)context.getSystemService(Context.TELEPHONY_SERVICE);
String did = tm.getDeviceId();
WebView myWebView = (WebView) findViewById(R.id.webview);
myWebView.loadUrl("/assets/index.html?DeviceID=" + did);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With