title: getting an error "java.lang.IllegalStateException: Can print only from an activity"?
body: <p>I am getting an error "<code>java.lang.IllegalStateException</code>: Can print only from an activity" while using an android 4.4 printing API.</p>
  
  <p>is it work on all android above 4.4?</p>
  
  <p>my code</p>
  
  <pre><code>public class MainActivity extends Activity {
  
      Context cotext;
      WebView mWebView;
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_main);
  
          cotext = getApplicationContext();
      }
  
      public void printData(View view){
          doWebViewPrint();
      }
  
      private void doWebViewPrint() {
          // Create a WebView object specifically for printing
          WebView webView = new WebView(cotext);
          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) cotext
                  .getSystemService(Context.PRINT_SERVICE);
  
          // Get a print adapter instance
          PrintDocumentAdapter printAdapter = webView.createPrintDocumentAdapter();
  
          // Create a print job with name and adapter instance
          String jobName = getString(R.string.app_name) + " Document";
          printManager.print(jobName, printAdapter,
                  new PrintAttributes.Builder().build());
  
          // Save the job object for later status checking
          //mPrintJobs.add(printJob);
      }
  }
  </code></pre>
  
  <p>please help me.</p>
  
  <p>is there any example of android wifi printing?</p>