Ao fazer uma foto com a câmera do android minha app cria um preview dessa 
foto em uma Activity onde será enviado por e-mail, porém o código abaixo 
está funcionando perfeitamente para o android abaixo da versão 4.4.1 e 
acima dela no momento de capturar o caminho da imagem para gerar o preview 
ele encerra a app e acusa nullPointerException e o result=-1. Alguém sabe 
me informar como faço para que também funcione nas versões acima do 4.4.1 
android?

Preview onde serão inseridas as fotos.

<LinearLayout
        android:id="@+id/previewFoto"
        android:orientation="vertical"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"></LinearLayout>

Código para a câmera:

private String caminhoFoto = "";
@Overrideprotected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_send__email);
  camera.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {

            Intent intentCamera = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
            caminhoFoto = getExternalFilesDir(null) + "/" + 
String.valueOf(System.currentTimeMillis()) + ".jpg";
            Log.i("CAMINHO",caminhoFoto);
            File arquivoFoto = new File(caminhoFoto);
            intentCamera.putExtra(MediaStore.EXTRA_OUTPUT, 
Uri.fromFile(arquivoFoto));
            startActivityForResult(intentCamera, CODIGO_CAMERA);
        }
    });

  @Overrideprotected void onActivityResult(int requestCode, int resultCode, 
Intent intent){
    if(resultCode == Activity.RESULT_OK){
        if(requestCode == CODIGO_CAMERA){
            carregaImagem(caminhoFoto);
        } else if(requestCode == CODIGO_GALERIA){
            try{
                listaImagem(intent);
            }catch (Exception e){
                e.printStackTrace();
            }
        }
    }}}
 private void carregaImagem(String caminhoFoto) {

    Bitmap bitmap = BitmapFactory.decodeFile(caminhoFoto);
    Bitmap bitmapReduzido = Bitmap.createScaledBitmap(bitmap, 300,300, true);

    LinearLayout lista = (LinearLayout) findViewById(R.id.previewFoto);

    ImageView foto = new ImageView(this);
    foto.setImageBitmap(bitmapReduzido);
    foto.setScaleType(ImageView.ScaleType.FIT_XY);

    lista.addView(foto);}

-- 
You received this message because you are subscribed to the Google Groups 
"Android Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to android-developers+unsubscr...@googlegroups.com.
To post to this group, send email to android-developers@googlegroups.com.
Visit this group at https://groups.google.com/group/android-developers.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/android-developers/7fd1dc2f-abe8-4381-9849-1832aa0dee9c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to