File generated in Android does not appear in windows Explorer

1

I can save the file on my micro sd but connect the mobile device on the computer through a USB file does not appear in Windows Explorer.

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

public void ExportarArquivoExterno() {

    String lstrNomeArq;
    File arq;
    byte[] dados;

    String txtSalvar = "texto do arquivo";

    try
    {
        //pega o nome do arquivo a ser gravado
        lstrNomeArq = "nomearquivo.txt";

        arq = new File("/storage/external_SD/Exportações", lstrNomeArq);

        FileOutputStream fos;

        //transforma o texto digitado em array de bytes
        dados = txtSalvar.toString().getBytes();

        fos = new FileOutputStream(arq);

        //escreve os dados e fecha o arquivo
        fos.write(dados);
        fos.flush();
        fos.close();

    } catch (Exception e) {

        //trace("Erro : " + e.getMessage());

    }        

}
    
asked by anonymous 10.12.2015 / 12:56

1 answer

0

As can be seen in this post on Android Stackexchange and In this report in google code , this is a bug that, depending on how the file is created on the device, is inaccessible when accessed by the computer, via MTP.

Try to follow this solution removed from SOEn , when setting file creation in your application:

MediaScannerConnection.scanFile (this, new String[] {file.toString()}, null, null);

Where file is the URI variable of your file, after it is created, or for versions smaller than 4.4 it is still possible to do:

sendBroadcast(new Intent(Intent.ACTION_MEDIA_MOUNTED, Uri.parse("file://"
            + Environment.getExternalStorageDirectory()))); 

You insert one of the lines of code just after the file creation code.

If you want more details, in this SOEn post and In this here there are other suggestions on how to work around this problem.

    
10.12.2015 / 13:39