문제

I am developing an android application in eclipse to print a report via Google Cloud Print. This tutorial from Google has me on the right track.
I have already installed itext to generate the Report.pdf

My problem is in the "print" element of my applications UI. Google supplies this code:

Intent printIntent = new Intent(this, PrintDialogActivity.class);
printIntent.setDataAndType(docUri, docMimeType);
printIntent.putExtra("title", docTitle);
startActivity(printIntent);

With the message:

"In the code above, replace the three parameters as follows: docUri - URI of the document to be printed docMimeType - MIME type of the document to be printed. We recommend that you use PDF (application/pdf) format docTitle - title of the printed document, arbitrary string that will be shown on the GCP management console as the print job's title

My PDF is saved at /data/Student/StudentReportPDF.pdf

I have tried changing the docUri, docMimeType and docTitle has follows: With no luck

Intent printIntent = new Intent(this, PrintDialogActivity.class);
printIntent.setDataAndType(StudentReportPDF, .pdf);
printIntent.putExtra("title", Student Report);
startActivity(printIntent);

All 3 elements result in red squigglies.

Can someone spot my mistake or I guess clarify these 3 elements for me?

printing eclipse-plugin pdf-generation itext google-cloud-print

도움이 되었습니까?

해결책

Big thanks to DragonRancher via Reddit

dragonrancher 1 point 1 hour ago When using the Java language, you need to put your strings between double quotes, otherwise they are interpreted as identifiers. Your putExtra line should probably look like:

printIntent.putExtra("title", "Student Report");

The setDataAndType line has other issues though. According to the documentation, the setDataAndType method requires a Uri object and a string containing a MIME type. In this case, you might be able to use the Uri.fromFile or Uri.parse methods to get a Uri object from your filename, and the MIME type for PDFs is application/pdf:

printIntent.setDataAndType(Uri.fromFile(new File("Report.pdf")), "application.pdf");

I don't actually have any experience with Android, so someone else might be able to better comment on determining the path for your report file.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top