title: Pass JavaScript Value from Webview to Activity?Android
body: <p>I followed <a href="https://download.epson-biz.com/modules/pos/index.php?page=single_soft&amp;cid=4601&amp;scat=50&amp;pcat=52" rel="nofollow noreferrer">this</a> to Print in android (<strong>Thermal Printer</strong>)</p>
  
  <p>This is <a href="https://jsfiddle.net/sL1pwp8b/" rel="nofollow noreferrer">My web-view</a> Over there On-click  It will Load My Android Activity Which is Out of Web-view...</p>
  
  <p>For that I have Given this... to Open new activity from web-view..</p>
  
  <pre><code>public class Main_web extends AppCompatActivity {
  
  private WebView webView;
  
  @Override
  public void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.main_m);
  
      webView = (WebView) findViewById(R.id.webm);
  
      WebSettings set = webView.getSettings();
      set.setJavaScriptEnabled(true);
      webView.setScrollBarStyle(WebView.SCROLLBARS_OUTSIDE_OVERLAY);
      final AlertDialog alertDialog = new AlertDialog.Builder(this).create();
      final ProgressDialog progressBar = ProgressDialog.show(Main_web.this, "Please Wait", "Loading...");
  
      webView.addJavascriptInterface(new WebAppInterface(this), "NewFUN");
      webView.requestFocusFromTouch();
      webView.setWebViewClient(new WebViewClient()
  
      {
  
          public void onPageFinished(WebView view, String url) {
  
              if (progressBar.isShowing()) {
                  progressBar.dismiss();
              }
          }
  
      });
  
      webView.setWebChromeClient(new WebChromeClient());
  
      String url = "www.google.com/m_app_eta.php";
      //String url = "file:///android_asset/tex.html";
      try {
  
          if (URLUtil.isValidUrl(url)) {
              webView.loadUrl(url);
  
          } else {
            //do something
          }
      } catch (Exception e) {
           //do something
  
      }
  
  }
  
  //Class to be injected in Web page
  
  public class WebAppInterface {
  
      Context mContext;
      WebAppInterface(Context c) {
          mContext = c;
      }
  
      @JavascriptInterface
      public void Print() {
  
          AlertDialog.Builder alertDialog = new AlertDialog.Builder(mContext);
          alertDialog.setTitle("Alert");
          alertDialog.setMessage("Are you sure you want to leave to next screen?");
          alertDialog.setPositiveButton("YES",
                  new DialogInterface.OnClickListener() {
                      public void onClick(DialogInterface dialog, int which) {
                          Intent chnIntent = new Intent(Main_web.this, Print_activity.class);
                          startActivity(chnIntent);
                      }
                  });
          alertDialog.setNegativeButton("NO",
                  new DialogInterface.OnClickListener() {
                      public void onClick(DialogInterface dialog, int which) {
                          dialog.cancel();
                      }
                  });
  
          alertDialog.show();
      }
  
  }
  }
  </code></pre>
  
  <p>Now My printer Activity is working Fine So here I want to pass a Value On click  Button Which Opens Printer... But can Any one suggest me How to Receive same value in android Activity not in web-view...</p>
  
  <p>All I need is In my web-view when I click on the Button its loading Android Activity Along with that I want to Pass A string value to new Activity</p>
  
  <p>Why Should I pass Value means In that I have a Url so I can Print with that URL 
  Here JS value is different form current URL</p>
  
  <p><strong>Update</strong></p>
  
  <p>I followed <a href="http://android-er.blogspot.in/2011/10/call-javascript-inside-webview-from.html" rel="nofollow noreferrer">this</a> But its Inside the Web-view I want same at Outside the web-view...</p>
  
  <p>Means When I click on the web-view Its opening android activity with the same its should pass a value to my activity not the web-view</p>
  
  <p><strong>Update 1</strong></p>
  
  <p>I followed @Sujal Mandal answer But I dont Know How to use that Value In next activity Can any one suggest me... on this kind... in next activity It may in <code>System.out.println</code> or <code>text-view</code> or any other <code>string</code> So I can use can Any one suggest How to Use the JavaScript Value in other activity outside the web-view..</p>