I'm finishing developing a form in android studio, where the user send an image along with info via email. I already managed to do everything, the problem now is when I take the photo and I'll send it to the email and a message appears:
Unable to attach due to e / s error
HereismyclasswhereIdevelopedmyform.
packagebr.com.diego.tecnologiadanet.fragments;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);img=(ImageView)view.findViewById(R.id.imageButton);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("image/jpeg");
File bitmapFile = new File(Environment.getExternalStorageDirectory()+"/image.jpg");
Uri myUri = Uri.fromFile(bitmapFile);
email.putExtra(Intent.EXTRA_STREAM, myUri);
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 == Activity.RESULT_OK){
try {
if(bitmap != null){
bitmap.recycle();
}
stream = getActivity().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;
}
I have searched and some comments say that I can not get the address where my photo was saved, is my code not doing this?