title: Catching a json response from a webview
body: <p><strong>What i am trying to do:</strong> </p>
  
  <ul>
  <li>I am loading a url into webview</li>
  <li>I am traversing 2 3 pages inside webview</li>
  <li>In the final page a transaction is done and a json response is
  returned</li>
  <li>I need to catch that response</li>
  </ul>
  
  <h2>How to achieve this IN ANDROID?</h2>
  
  <p>currently i have successfully loaded the url </p>
  
  <p>Myclass.java</p>
  
  <pre><code>public class Myclass extends ActionBarActivity{
  
      public static Context context = null;
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.act_buycredits);
  
          context = this;
  
  
          getSupportActionBar().setDisplayHomeAsUpEnabled(true);
          getSupportActionBar().setBackgroundDrawable(
                  new ColorDrawable(getResources().getColor(
                          R.color.windhya_actionbar_color)));
          // ////////////////-------SUPORT---MENU----IRRESPECTIVE--OF---VERSIONS---////////////////////////////
          try {
              ViewConfiguration config = ViewConfiguration.get(this);
              Field menuKeyField = ViewConfiguration.class
                      .getDeclaredField("sHasPermanentMenuKey");
              if (menuKeyField != null) {
                  menuKeyField.setAccessible(true);
                  menuKeyField.setBoolean(config, false);
              }
          } catch (Exception ex) {
              // Ignore
          }
  
          // ////////////////-------SUPORT---MENU----IRRESPECTIVE--OF---VERSIONS---////////////////////////////
  
  
      }
  
  
      @Override
      public boolean onOptionsItemSelected(MenuItem item) {
  
          int itemId = item.getItemId();
          switch (itemId) {
          case android.R.id.home:
             finish();
  
              // Toast.makeText(this, "home pressed", Toast.LENGTH_LONG).show();
              break;
  
          }
  
          return true;
      }
  
      @Override
      public void onBackPressed() {
          MyWebViewFragment fragment = (MyWebViewFragment)getFragmentManager().findFragmentById(R.id.myweb_fragment);
          WebView webView = fragment.myWebView;
  
          if(webView.canGoBack()){
              webView.goBack();
          }else{
              super.onBackPressed();
          }
      }
  
  
      static public class MyWebViewFragment extends Fragment {
  
          WebView myWebView;
          //final static String myBlogAddr = "https://www.payumoney.com/";
  
          //final static String myBlogAddr = "https://entech1.cloudapp.net:8001/paymentGateWay/";
  
  
          final static String myBlogAddr = Keys.pamentGateway_api;
  
          String myUrl;
  
  
          @Override
          public View onCreateView(LayoutInflater inflater, ViewGroup container,
                  Bundle savedInstanceState) {
  
              View view = inflater.inflate(R.layout.layout_webfragment, container, false);
  
              myWebView = (WebView)view.findViewById(R.id.mywebview);
  
              myWebView.getSettings().setJavaScriptEnabled(true);                
              myWebView.setWebViewClient(new MyWebViewClient());
  
              if(myUrl == null){
                  myUrl = myBlogAddr;
              }
  
              Map &lt;String, String&gt; extraHeaders = new HashMap&lt;String, String&gt;();
              extraHeaders.put("phonenumber",AppController.getPhoneNumber()); 
              extraHeaders.put("authtoken",AppController.getAuthCode()); 
  
              this.myWebView.getSettings().setRenderPriority(RenderPriority.HIGH);
              this.myWebView.getSettings().setPluginState(android.webkit.WebSettings.PluginState.ON_DEMAND);
              this.myWebView.getSettings().setJavaScriptEnabled(true);
              this.myWebView.getSettings().setDomStorageEnabled(true);
              this.myWebView.setLayerType(View.LAYER_TYPE_SOFTWARE, null);
  
  
  
              this.myWebView.setWebChromeClient(new WebChromeClient(){
                  @Override
                  public boolean onJsAlert(WebView view, String url,
                          String message, JsResult result) {
                      // TODO Auto-generated method stub
  
                      Toast.makeText(context, message, 5000).show();
                      //Toast.makeText(context, super.onJsAlert(view, url, message, result)+"", 5000).show();
                      return false;
                      //return super.onJsAlert(view, url, message, result);
                  }
              });
              myWebView.loadUrl(myUrl,extraHeaders);
  
  
  
              return view;
  
          }
  
          private class MyWebViewClient extends WebViewClient {
              @Override
              public boolean shouldOverrideUrlLoading(WebView view, String url) {
                  myUrl = url;
                  view.loadUrl(url);
                  return true;
              }
          }
  
          @Override
          public void onActivityCreated(Bundle savedInstanceState) {
              super.onActivityCreated(savedInstanceState);
              setRetainInstance(true);
          }
  
      }
  }
  </code></pre>
  
  <p><strong><em>hOW TO ACHIEVE THIS</em></strong></p>