Bom dia.
Tenho o seguinte pedaço de código:
public void onTakePicture(View view) {
Intent cameraIntent = new Intent(
android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
String path = Environment.getExternalStorageDirectory().getPath()
+ File.separatorChar + "SRec" + File.separatorChar;
try {
this.camImg = path;
this.arqImg = "imagem.jpg";
createDirIfNotExists(this.camImg);
File file = new File(this.camImg + this.arqImg);
file.createNewFile();
// Salva direto no arquivo
Uri outputFileUri = Uri.fromFile(file);
cameraIntent.putExtra(MediaStore.EXTRA_OUTPUT, outputFileUri);
startActivityForResult(cameraIntent, CAMERA_PIC_REQUEST);
} catch (Exception er) {
Log.e(Constantes.TAG, er.getMessage());
}
}
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if ((requestCode == CAMERA_PIC_REQUEST)
&& (resultCode == Activity.RESULT_OK)) {
File file = new File(this.camImg + this.arqImg);
if (file.exists()) {
this.camZip = this.camImg;
this.arqZip = "env." + getDateTime() + "."
+ AndroidIdentificacao.id(getApplicationContext())
+ ".zip";
compress(new String[] { this.camImg + this.arqImg },
this.camZip + this.arqZip);
enviaFTP("backup", "backup", this.camZip + this.arqZip,
this.arqZip);
File zip = new File(this.camZip + this.arqZip);
if (zip.exists()) {
deleteFile(this.camZip + this.arqZip);
}
}
}
}
O código esta funcionando.
Mas ao fazer testes em celulares, em celulares e tablets funciona bem, exceto quando fui fazer o teste no Samsung Galaxy S2.
Percebi que depurando o código tudo funciona perfeitamente.
Mas ao rodar o aplicativo sem depuração no aparelho, quando entra no metodo onActivityResult, o arquivo que foi colocado no putExtra para ser salvo a imagem, ainda não existe.
Parece que ainda não rodou o flush para o disco ou que o processo neste aparelho é muito mais rapido que a gravação do arquivo no disco.
Como tratar isto, ter certeza que gravou o arquivo, ou em vez de gravar em disco a imagem, gravar em um Buffer para fazer a compactação e envio do arquivo?
Usando o Bitmap direto também acontece a mesma coisa, e no caso a imagem é pequena o que não serve para o meu caso.