0

How to send string in web view or javascript function from android ?

Could you please tell me why this is not working ?I am trying to call javascript function from android I am taking help form here Android Calling JavaScript functions in WebView

This is working fine

webView.loadUrl("javascript:testEcho('hello')");

Why this is not working ?

String str = "hello sharma";

webView.loadUrl("javascript:testEcho("+str+")");
user944513
  • 11,195
  • 34
  • 140
  • 266

1 Answers1

0

You will need to add quotes around the string variable so it is considered a string.

webView.loadUrl("javascript:testEcho('"+str+"')");

Without them, it will be considered a variable in javascript.

Karan
  • 1,156
  • 2
  • 8
  • 15