Create folder in device's internal memory and display message after recording

-1

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
    }
}
    
asked by anonymous 05.06.2014 / 02:58

1 answer

1

Try this, here it works on all APIs.

  private File getDirFromSDCard() {
        if (Environment.getExternalStorageState().equals(
                Environment.MEDIA_MOUNTED)) {
            File sdcard = Environment.getExternalStorageDirectory()
                    .getAbsoluteFile();
            File dir = new File(sdcard, "APP_NAME" + File.separator + "PASTA_1");
            if (!dir.exists())
                dir.mkdirs();
            return dir;
        } else {
            return null;
        }
    }
    
05.06.2014 / 17:03