Olá mestres em Android.
alguém me ajuda nisso, pfv?
Minha app funciona perfeitamente, porém para quando aciona a câmera. pelo que vi, os códigos estão ok, mas quem puder ajudar me deixaria grato!
att
Vitor
package br.com.alura.agenda40;
import android.app.Activity;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.net.Uri;
import android.provider.MediaStore;
import android.support.annotation.Nullable;
import android.support.v4.app.ActivityCompat;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.Toast;
import java.io.File;
import br.com.alura.agenda40.dao.AlunoDAO;
import br.com.alura.agenda40.modelo.Aluno;
public class formulario extends AppCompatActivity {
public static final int CODIGO_CAMERA = 567;
private formularioHelper helper;
private String caminhoFoto;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_formulario);
helper = new formularioHelper(this);
Intent intent = getIntent();
Aluno aluno = (Aluno) intent.getSerializableExtra("aluno");
if(aluno!= null){
helper.preencheFormulario(aluno);
}
Button botaoFoto= (Button) findViewById(R.id.formulario_botao_foto);
botaoFoto.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent intentCamera = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
caminhoFoto = getExternalFilesDir(null)+"/"+System.currentTimeMillis()+".jpg";
File arquivoFoto = new File(caminhoFoto);
intentCamera.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(arquivoFoto));
startActivityForResult(intentCamera,CODIGO_CAMERA);
}
});
}
@Override
protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
Toast.makeText(this,"Eita", Toast.LENGTH_SHORT).show();
if(resultCode == Activity.RESULT_OK) {
Toast.makeText(this,"Entrou", Toast.LENGTH_SHORT).show();
if (requestCode == CODIGO_CAMERA) {
ImageView foto = (ImageView) findViewById(R.id.formulario_foto);
Bitmap bitmap = BitmapFactory.decodeFile(caminhoFoto);
Bitmap bitmapreduzido = Bitmap.createScaledBitmap(bitmap, 200, 200, true);
foto.setImageBitmap(bitmapreduzido);
foto.setScaleType(ImageView.ScaleType.FIT_XY);
}
}
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater =getMenuInflater();
inflater.inflate(R.menu.menu_formulario, menu);
return super.onCreateOptionsMenu(menu);
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.menu_formulario_ok:
AlunoDAO dao = new AlunoDAO(this);
Aluno aluno =helper.pegaAluno();
if(aluno.getId()!=null){
dao.altera(aluno);
}else {
dao.insere(aluno);
}
dao.close();
Toast.makeText(formulario.this, "Aluno "+aluno.getNome()+" Salvo", Toast.LENGTH_SHORT).show();
finish();
break;
}
return super.onOptionsItemSelected(item);
}
}
insira seu código aqui