No onCreate
mBotFoto.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
try {
mFileTemp = new File(getActivity().getCacheDir(), "temp_photo2.jpg");
uri = FileProvider.getUriForFile(getContext(), "br.com.legalestudioapp.legalmototaxiagente.fileprovider2", mFileTemp);
intent.putExtra(android.provider.MediaStore.EXTRA_OUTPUT, uri);
intent.putExtra("return-data", true);
intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
startActivityForResult(intent, IMAGEM_CAMERA);
} catch (ActivityNotFoundException e) {
Toast.makeText(getContext(), "Não foi possível abrir a câmera!", Toast.LENGTH_LONG).show();
}
}
});
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
if (resultCode == Activity.RESULT_OK) {
if (requestCode == IMAGEM_CAMERA) {
if (mFileTemp == null) {
Toast.makeText(getContext(), "nao carregou foto da camera", Toast.LENGTH_LONG).show();
return;
}
//Uri uri = FileProvider.getUriForFile(getActivity().getApplicationContext(), "br.com.legalestudioapp.legalmototaxiagente.fileprovider", mFileTemp);
// Intent i=new Intent(Intent.ACTION_VIEW, FileProvider.getUriForFile(this, AUTHORITY, mFileTemp));
try {
Intent cropIntent = new Intent("com.android.camera.action.CROP");
cropIntent.setDataAndType(uri, "image/*");
cropIntent.putExtra("crop", "true");
cropIntent.putExtra("aspectX", 1);
cropIntent.putExtra("aspectY", 1);
cropIntent.putExtra("outputX", 640);
cropIntent.putExtra("outputY", 640);
cropIntent.putExtra("return-data", true);
cropIntent.putExtra("noFaceDetection", true);
cropIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
startActivityForResult(cropIntent, PIC_CROP);
} catch (Exception e) {
Toast.makeText(getContext(), "não foi possível editar", Toast.LENGTH_LONG).show();
Bundle extras = data.getExtras();
//get the cropped bitmap
Bitmap foto = extras.getParcelable("data");
mFotoC.setImageBitmap(foto);
mFoto = foto;
Long tsLong = System.currentTimeMillis() / 1000;
timestamp = tsLong.toString();
}
}
if (requestCode == PIC_CROP) {
Bundle extras = data.getExtras();
//get the cropped bitmap
Bitmap foto = extras.getParcelable("data");
mFotoC.setImageBitmap(foto);
mFoto = foto;
Long tsLong = System.currentTimeMillis() / 1000;
timestamp = tsLong.toString();
}
}
}