title: Document Missing for android google cloud print
body: <p>I have a simple application in android. Which has two activity.One is Document.Activity with layout xml is butt.xml. And another one is PrintDialogActivity with print_dialog.xml. I share my printer and everything is ok.But When I select my share printer and click the print button in google cloud print, a black titlebar with "Document Missing" appear. Now what can I do? Please help me..</p>
  
  <p>Here is my Document Activity:</p>
  
  <pre><code>public class Document extends Activity{
  
  Button btnprt;
  
  @Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.butt);
  
      btnprt = (Button) findViewById(R.id.button1);
      btnprt.setOnClickListener(new View.OnClickListener() {
  
          @Override
          public void onClick(View v) {
              // TODO Auto-generated method stub
                  Intent printIntent = new Intent(Document.this, PrintDialogActivity.class);
                  //File file = new File("/sdcard/StudentLatePass.txt");
                  //printIntent.setDataAndType(Uri.fromFile(file), "text/*");
                  Uri docUri = Uri.parse("http://www.google.com");
                  //String ur = docUri.toString();
                  printIntent.setDataAndType(docUri, "application/pdf");
                  printIntent.putExtra("title", "StudentLatePass");
                  startActivity(printIntent);
          }
      });
  }
  </code></pre>
  
  <p>}</p>
  
  <p>Here is my butt.xml:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
   &lt;RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
   android:layout_width="match_parent"
   android:layout_height="match_parent" &gt;
  
   &lt;Button
      android:id="@+id/button1"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:layout_alignParentTop="true"
      android:layout_centerHorizontal="true"
      android:layout_marginTop="114dp"
      android:text="Print" /&gt;
  
    &lt;/RelativeLayout&gt;
  </code></pre>
  
  <p>Here is my PrintDialogActivity:</p>
  
  <pre><code> public class PrintDialogActivity extends Activity {
    private static final String PRINT_DIALOG_URL = "https://www.google.com/cloudprint     /dialog.html";
    private static final String JS_INTERFACE = "AndroidPrintDialog";
    private static final String CONTENT_TRANSFER_ENCODING = "base64";
  
    private static final String ZXING_URL = "http://zxing.appspot.com";
    private static final int ZXING_SCAN_REQUEST = 65743;
  
    /**
     * Post message that is sent by Print Dialog web page when the printing dialog
     * needs to be closed.
     */
    private static final String CLOSE_POST_MESSAGE_NAME = "cp-dialog-on-close";
  
    /**
     * Web view element to show the printing dialog in.
     */
    private WebView dialogWebView;
  
    /**
     * Intent that started the action.
     */
    Intent cloudPrintIntent;
  
    @Override
    public void onCreate(Bundle icicle) {
      super.onCreate(icicle);
  
      setContentView(R.layout.print_dialog);
      dialogWebView = (WebView) findViewById(R.id.webview);
      cloudPrintIntent = this.getIntent();
  
      WebSettings settings = dialogWebView.getSettings();
      settings.setJavaScriptEnabled(true);
  
      dialogWebView.setWebViewClient(new PrintDialogWebClient());
      dialogWebView.addJavascriptInterface(
        new PrintDialogJavaScriptInterface(), JS_INTERFACE);
  
      dialogWebView.loadUrl(PRINT_DIALOG_URL);
    }
  
    @Override
    public void onActivityResult(int requestCode, int resultCode, Intent intent) {
      if (requestCode == ZXING_SCAN_REQUEST &amp;&amp; resultCode == RESULT_OK) {
        dialogWebView.loadUrl(intent.getStringExtra("SCAN_RESULT"));
      }
    }
  
    final class PrintDialogJavaScriptInterface {
      public String getType() {
        return cloudPrintIntent.getType();
      }
  
      public String getTitle() {
        return cloudPrintIntent.getExtras().getString("title");
      }
  
      public String getContent() {
        try {
          ContentResolver contentResolver = getContentResolver();
          InputStream is = contentResolver.openInputStream(cloudPrintIntent.getData());
          ByteArrayOutputStream baos = new ByteArrayOutputStream();
  
          byte[] buffer = new byte[4096];
          int n = is.read(buffer);
          while (n &gt;= 0) {
            baos.write(buffer, 0, n);
            n = is.read(buffer);
          }
          is.close();
          baos.flush();
  
          return Base64.encodeToString(baos.toByteArray(), Base64.DEFAULT);
        } catch (FileNotFoundException e) {
          e.printStackTrace();
        } catch (IOException e) {
          e.printStackTrace();
        }
        return "";
      }
  
      public String getEncoding() {
        return CONTENT_TRANSFER_ENCODING;
      }
  
      public void onPostMessage(String message) {
        if (message.startsWith(CLOSE_POST_MESSAGE_NAME)) {
          finish();
        }
      }
    }
  
    private final class PrintDialogWebClient extends WebViewClient {
      @Override
      public boolean shouldOverrideUrlLoading(WebView view, String url) {
        if (url.startsWith(ZXING_URL)) {
          Intent intentScan = new Intent("com.google.zxing.client.android.SCAN");
          intentScan.putExtra("SCAN_MODE", "QR_CODE_MODE");
          try {
            startActivityForResult(intentScan, ZXING_SCAN_REQUEST);
          } catch (ActivityNotFoundException error) {
            view.loadUrl(url);
          }
        } else {
          view.loadUrl(url);
        }
        return false;
      }
  
      @Override
      public void onPageFinished(WebView view, String url) {
        if (PRINT_DIALOG_URL.equals(url)) {
          // Submit print document.
          view.loadUrl("javascript:printDialog.setPrintDocument(printDialog.createPrintDocument("
            + "window." + JS_INTERFACE + ".getType(),window." + JS_INTERFACE + ".getTitle(),"
            + "window." + JS_INTERFACE + ".getContent(),window." + JS_INTERFACE + ".getEncoding()))");
  
          // Add post messages listener.
          view.loadUrl("javascript:window.addEventListener('message',"
              + "function(evt){window." + JS_INTERFACE + ".onPostMessage(evt.data)}, false)");
        }
      }
    }
  }
  </code></pre>
  
  <p>Here is my print_dialog.xml:</p>
  
  <pre><code>&lt;RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
              android:layout_width="fill_parent"
              android:layout_height="fill_parent"&gt; 
   &lt;WebView android:id="@+id/webview"
         android:layout_width="fill_parent" 
         android:layout_height="fill_parent"/&gt; 
  </code></pre>
  
  <p></p>