Question

I'm building an app that has to print a file. I want to use Google cloud print but it keeps saying the file is missing.

The app creates a pdf using iText. This part works, Adobe reader can show it on my phone. Then I run this:

public static final String FILE_URI = Environment.getExternalStorageDirectory().getPath() + "/pdfFile.pdf";

Uri uri = Uri.parse(FILE_URI);

Intent printIntent = new Intent(MainActivity.this, PrintDialogActivity.class);
printIntent.setDataAndType(uri, "pdf");
printIntent.putExtra("title", "pdfFile");
startActivity(printIntent);

It launches the print activity, you can log in to your google account but when you press print it says document missing. Anyone knows what's wrong?

Was it helpful?

Solution

Instead of using the following:

Uri uri = Uri.parse(FILE_URI); 

and

printIntent.setDataAndType(uri, "pdf");

use:

Uri uri = Uri.fromFile(new File(Environment.getExternalStorageDirectory().getAbsolutePath()+"/output.pdf"));

and

printIntent.setDataAndType(uri, "application/pdf");

It works :)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top