title: How to add print support in android webview
body: <p>Hello ppl i have created one android application using android webview.
  In the url that i have loaded in webview has print options in some place. Actually i have 
  stuck with   <a href="https://developer.android.com/training/printing/html-docs.html" rel="nofollow noreferrer">this tutorial</a>. could anybody tell where can i implement that doWebViewPrint() method 
  in my project. if anybody know better tutorial site means please let me know</p>
  
  <p>Here is my Mainactivity</p>
  
  <pre><code>public class MainActivity extends AppCompatActivity {
          public WebView webView;
          public WebView mWebView
          ProgressBar progressBar;
          ArrayList&lt;PrintJob&gt; printJobs = new ArrayList&lt;PrintJob&gt;();
          @Override
          protected void onCreate(Bundle savedInstanceState) {
              super.onCreate(savedInstanceState);
              setContentView(R.layout.activity_main);
              webView = (WebView)findViewById(R.id.web);
              progressBar = (ProgressBar)findViewById(R.id.progressBar1);
              webView.setWebViewClient(new overload());
              setProgressBarVisibility(View.VISIBLE);
              webView.setWebViewClient(new WebViewClient() {
                   @Override
                  public void onPageStarted(WebView view, String url, Bitmap favion){
                      super.onPageStarted(view,url,favion);
                      setProgressBarVisibility(View.VISIBLE);
                  }
                  @Override
                  public void onPageFinished(final WebView view, String url) {
                      //hide loading image
                      findViewById(R.id.imageLoading1).setVisibility(View.GONE);
                      //hide progressbar
                      setProgressBarVisibility(View.GONE);
                      //show webview
                      findViewById(R.id.web).setVisibility(View.VISIBLE);
                     // doWebViewPrint();
                   }
              });
              webView.loadUrl(url);
              webView.loadUrl("javascript:var footer = document.getElementById(\"footer\"); footer.parentNode.removeChild(footer); ");
              WebSettings webSettings = webView.getSettings();
              if (Build.VERSION.SDK_INT &gt;= Build.VERSION_CODES.JELLY_BEAN) {
                  webSettings.setAllowUniversalAccessFromFileURLs(true);
              }
              webSettings.setAllowFileAccessFromFileURLs(true);
              webSettings.setJavaScriptEnabled(true);
              webSettings.setLoadWithOverviewMode(true);
  
          }
        private void doWebViewPrint() {
      // Create a WebView object specifically for printing
      WebView webView = new WebView(MainActivity.this);
      webView.setWebViewClient(new WebViewClient() {
  
      public boolean shouldOverrideUrlLoading(WebView view, String url) {
      return false;
      }
  
      @Override
      public void onPageFinished(WebView view, String url) {
      Log.i(TAG, "page finished loading " + url);
      createWebPrintJob(view);
      mWebView = null;
      }
      });
  
      // Generate an HTML document on the fly:
      String htmlDocument = "&lt;html&gt;&lt;body&gt;&lt;h1&gt;Test Content&lt;/h1&gt;&lt;p&gt;Testing, " +
      "testing, testing...&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;";
      webView.loadDataWithBaseURL(null, htmlDocument, "text/HTML", "UTF-8", null);
  
      // Keep a reference to WebView object until you pass the PrintDocumentAdapter
      // to the PrintManager
      mWebView = webView;
      }
    private void createWebPrintJob(WebView webView) {
  
      // Get a PrintManager instance
      PrintManager printManager = (PrintManager) MainActivity.this
              .getSystemService(Context.PRINT_SERVICE);
  
      String jobName = getString(R.string.app_name) + " Document";
  
      // Get a print adapter instance
      PrintDocumentAdapter printAdapter = webView.createPrintDocumentAdapter(jobName);
  
      // Create a print job with name and adapter instance
      PrintJob printJob = printManager.print(jobName, printAdapter,
              new PrintAttributes.Builder().build());
  
      printJobs.add(printJob);
  }
  }
  </code></pre>