I have two problems.
The Toast
in my method returns the following error:
The method makeText (Context, CharSequence, int) in the type Toast is not applicable for the arguments (GenerateReport, String, int)
How to display a standard error message? Such as " Document not created ".
To create the folder I am using this code, I tested the emulator and nothing happened, creating the PDF file in the Documents folder with this line of the right:
File path = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOCUMENTS);
But only in API 19 , so I wanted to create the folder and check whether it exists or not, so I can use it on Android 4.0. >
public void CriarRelatorio(ClienteClass objCliente, EquipamentoClass objEquipamento, ServicoClass objServico, PecasClass objPecas){
try {
Document document = new Document();
File direct = new File(Environment.getExternalStorageDirectory()+"/Relatorios");
if(!direct.exists()) {
if(direct.mkdir()); //se não existir o diretorio e criado
}
File pdffile = new File(direct, "RelatorioTeste.pdf");
PdfWriter.getInstance(document, new FileOutputStream(pdffile));
document.open();
addMetaData(document);
addTituloRelatorio(document);
addConteudo(document);
document.close();
Toast.makeText(this, "Arquivo criado com sucesso", Toast.LENGTH_SHORT).show();
} catch (Exception e) {
// TODO: handle exception
}
}