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
  • 9,790
  • 23
  • 109
  • 225

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
  • 931
  • 1
  • 6
  • 13