I am new to java script using in android,I have function in js file to convert user name,how to send i/p values to this and how to retrieve data for this file in android activity button click.if any one have idea please tell me thanks in advance.
1 Answer
tru out this :
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
web = (WebView) findViewById(R.id.webview1);
web.setWebChromeClient(new MyWebChromeClient());
web.addJavascriptInterface(new DemoJavaScriptInterface(), "temp_1");
web.loadUrl("file:///android_asset/temp_1.html");
}
}
final class DemoJavaScriptInterface {
private Handler mHandler = new Handler();
WebView web;
DemoJavaScriptInterface() {
}
public void clickOnAndroid() {
mHandler.post(new Runnable() {
public void run() {
web.loadUrl("javascript:init();");
}
});
} }
final class MyWebChromeClient extends WebChromeClient {
private static final String LOG_TAG = "WebViewDemo";
@Override
public boolean onJsAlert(WebView view, String url, String message, JsResult result) {
Log.e(LOG_TAG, message);
result.confirm();
return true;
}
}