2

I am using google cloud print with an android project to print out a pdf file. I am storing the file in the assets folder of the project and when I go to print it say "Document Missing".

Here is my code

public void stevePrint(View view) {
    Intent printIntent = new Intent(this, PrintDialogActivity.class);
    //Cant find file, why?
    File file = new File("/assets/steve.pdf");
    printIntent.setDataAndType(Uri.fromFile(file), "document/pdf");
    printIntent.putExtra("title", "Steve");
    startActivity(printIntent);

    Context context = getApplicationContext();
    CharSequence text = "Sending to Google Cloud Print";
    int duration = Toast.LENGTH_LONG;

    Toast toast = Toast.makeText(context, text, duration);
    toast.show();
}

Any help is appreciated!

wiiwilleat
  • 209
  • 2
  • 13

1 Answers1

9

You appear to be using the wrong MIME type. It should read:

printIntent.setDataAndType(Uri.fromFile(file), "application/pdf");

It looks like you're using PrintDialogActivity, from the Google Cloud Print documentation. Make sure to also add the @JavascriptInterface annotations to each method inside PrintDialogJavaScriptInterface.

Paul Lammertsma
  • 37,593
  • 16
  • 136
  • 187
  • 2
    This should be marked as the answer. Also if anyone happens to be able to run cloud print but the print button won't work, please make sure to import android.webkit.JavascriptInterface; and add the @JavascriptInterface as stated by Paul. I have been seeking how to solve that for weeks. It's easy to overlook. Thank you very much Paul! – ChallengeAccepted Nov 15 '14 at 10:28
  • Done trying all the above things.. Still getting the same issue of Document Missing. Can some body get help me on this. – Gaurang Oct 15 '15 at 08:48