Tecnologia do Blogger.
RSS

[androidbrasil-dev] Re: Salvar imagem e recuperar de diretório específico

Consegui resolver, e para quem possa interessar, mudou o código que salva a imagem:

String pathInternal = contexto.getApplicationContext().getFilesDir().getPath() + File.separator + param;

File newFile = new File(pathInternal);
newFile.createNewFile();

FileOutputStream fos = new FileOutputStream(newFile);
fos.write(response);
fos.close();

Att

Em segunda-feira, 23 de março de 2015 21:49:40 UTC-3, Luciano Pimenta escreveu:
Boa noite,
Estou fazendo o download de uma imagem e salvando no device:

URL url = new URL(urlImagem);
        InputStream in = new BufferedInputStream(url.openStream());
        ByteArrayOutputStream out = new ByteArrayOutputStream();

        try {

            byte[] buf = new byte[1024];
            int n = 0;

            while (-1!=(n=in.read(buf)))
            {
                out.write(buf, 0, n);
            }

            byte[] response = out.toByteArray();

            //salva na memória
            try{

                String pathInternal = contexto.getApplicationContext().getFilesDir().getPath() + "/" + param;
                FileOutputStream fos = contexto.openFileOutput(pathInternal, Context.MODE_PRIVATE);
                fos.write(response);
                fos.close();

            }catch (IOException e) {
                
            }

        } catch (Exception e) {

            e.printStackTrace();

        } finally {

            try {  out.close(); } catch (Exception e1) {}
            try {  in.close(); } catch (Exception e2) {}

        }

Após isso (debuguei e não gera nenhum erro), quando tento recuperar a imagem:

String file = getApplicationContext().getFilesDir().getPath() + "/" + nomedoArquivo;
File imgFile = new  File(file);

O retorno de imgFile.exists() é sempre falso.
Não consegui, usando um gerenciador de arquivos, ter a certeza que a imagem foi salva em memória do device (nem a pasta da app aparece em Android>data).

Como saber se ela foi salva e poder recuperar a mesma?
Agradeço qualquer ajuda.

Att

Luciano Pimenta

--
You received this message because you are subscribed to the Google Groups "Android Brasil - Dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to androidbrasil-dev+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

  • Digg
  • Del.icio.us
  • StumbleUpon
  • Reddit
  • RSS

0 comentários:

Postar um comentário