Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using Google Cloud Print in Android

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!

like image 295
wiiwilleat Avatar asked Dec 14 '25 23:12

wiiwilleat


1 Answers

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.

like image 190
Paul Lammertsma Avatar answered Dec 16 '25 15:12

Paul Lammertsma



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!