Error implementing method to take photo by application

4

I want to add the method of taking pictures by the application only when running my application error:

belowismyformclasscode:

Spinneroption;ButtonbtnSend;EditTextNome;EditTextMessage;EditTextEndereco;EditTextTelefone;EditTextEmail;ImageViewimg;privateBitmapbitmap;@OverridepublicViewonCreateView(LayoutInflaterinflater,ViewGroupcontainer,BundlesavedInstanceState){Viewview=inflater.inflate(R.layout.reclame,container,false);img=(ImageView)view.findViewById(R.id.imageButton);img.setOnClickListener(newView.OnClickListener(){@OverridepublicvoidonClick(Viewv){abrirCamera();}});Nome=(EditText)view.findViewById(R.id.nome1);Message=(EditText)view.findViewById(R.id.msg);Endereco=(EditText)view.findViewById(R.id.endereco);Telefone=(EditText)view.findViewById(R.id.telefone);Email=(EditText)view.findViewById(R.id.email);btnSend=(Button)view.findViewById(R.id.send);option=(Spinner)view.findViewById(R.id.spinner);option.setOnItemSelectedListener(this);ArrayAdapteradapter=ArrayAdapter.createFromResource(getActivity(),R.array.option,android.R.layout.simple_spinner_item);option.setAdapter(adapter);btnSend.setOnClickListener(newView.OnClickListener(){@OverridepublicvoidonClick(Viewv){Stringnome=Nome.getText().toString();Stringmessage=Message.getText().toString();Stringmatricula=Endereco.getText().toString();Stringtelefone=Telefone.getText().toString();Stringassunto=option.getSelectedItem().toString();Stringema=Email.getText().toString();Intentemail=newIntent(Intent.ACTION_SEND);email.putExtra(Intent.EXTRA_EMAIL,newString[]{"[email protected]"});
            email.putExtra(Intent.EXTRA_SUBJECT, assunto);
            email.putExtra(Intent.EXTRA_TEXT, "Nome: " +nome +'\n'+  "Endereço: "+matricula + '\n'+ "Telefone: "+telefone + '\n'+ "E-mail: "+ema + '\n'+ '\n'+message);


            email.setType("message/rfc822");
            startActivity(Intent.createChooser(email, "Selecione o serviço de e-mail:"));
        }
    });
    return view;
}

@Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
    TextView mtext = (TextView) view;
    //Toast.makeText(getActivity(), "Você selecionou: "+mtext.getText(), Toast.LENGTH_SHORT).show();
}

@Override
public void onNothingSelected(AdapterView<?> parent) {

}

public void abrirCamera(){
    Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
    startActivityForResult(intent, 0);
}

public void onActivityResult(int requestCode, int resultCode, Intent data){
    super.onActivityResult(requestCode, resultCode, data);
    InputStream stream = null;
    if(requestCode == 0 && resultCode == RESULT_OK){
        try {
            if(bitmap != null){
                bitmap.recycle();
            }
            stream = getContentResolver().openInputStream(data.getData());
            bitmap = BitmapFactory.decodeStream(stream);
            img.setImageBitmap(resizeImage(getActivity(), bitmap, 700, 600));
        }catch (FileNotFoundException e){
            e.printStackTrace();
        }finally {
            if (stream != null)
                try {
                    stream.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
        }
    }
}

private static Bitmap resizeImage (Context context, Bitmap bpmOriginal, float newWidth, float newHeight){
    Bitmap novoBpm = null;
    int w = bpmOriginal.getWidth();
    int h = bpmOriginal.getHeight();
    float densityFactor = context.getResources().getDisplayMetrics().density;
    float novoW = newWidth * densityFactor;
    float novoH = newHeight * densityFactor;

    float scalaW = novoW /w;
    float scalaH = novoH /h;
    Matrix matrix = new Matrix();
    matrix.postScale(scalaW, scalaH);
    novoBpm = Bitmap.createBitmap(bpmOriginal, 0, 0, w, h, matrix, true);
    return novoBpm;
}

What's wrong? and how to send the image along with the form information by email?

    
asked by anonymous 29.05.2016 / 17:10

1 answer

1

TLDR:

Use getActivity().getContentResolver() where you have getContentResolver() .

Your error says clearly:

  

error: can not find symbol getContentResolver () method

Because in the onActivityResult method you declare:

stream = getContentResolver().openInputStream(data.getData());

and the method getContentResolver needs a Context , which you do not have. Simply provide the context:

stream = getActivity().getContentResolver().openInputStream(data.getData());
    
30.05.2016 / 00:12