Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how can Send parameters to a local file in a WebView in android?

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.

like image 735
Android Avatar asked Nov 09 '22 18:11

Android


1 Answers

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);
like image 56
Prahlad Yeri Avatar answered Nov 14 '22 21:11

Prahlad Yeri