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.






0 comentários:
Postar um comentário