I have made a feedback form in my android app.
What I want is that I want to get all the text filled in that form (editText
) to be delivered to my email address without opening any other app or so.
I was unable to figure out how to do this but then I thought of a way, this is what I have done so far:
EditText etUserLikeResponse = (EditText) findViewById(R.id.user_like_response);
EditText etUserDontLikeResponse = (EditText) findViewById(R.id.user_dont_like_response);
EditText etUserOtherFeaturesResponse = (EditText) findViewById(R.id.user_other_features_response);
String etUserLikeResponseText = etUserLikeResponse.getText().toString();
String etUserDontLikeResponseText = etUserDontLikeResponse.getText().toString();
String etUserOtherFeaturesResponseText = etUserOtherFeaturesResponse.getText().toString();
Uri etUserLikeResponseTextUri = Uri.parse(etUserLikeResponseText);
Uri etUserDontLikeResponseTextUri = Uri.parse(etUserDontLikeResponseText);
Uri etUserOtherFeaturesResponseTextUri = Uri.parse(etUserOtherFeaturesResponseText);
final ArrayList<Uri> userResponseUri = new ArrayList<>();
userResponseUri.add(etUserLikeResponseTextUri);
userResponseUri.add(etUserDontLikeResponseTextUri);
userResponseUri.add(etUserOtherFeaturesResponseTextUri);
Button btnSendFeedback = (Button) findViewById(R.id.btn_send_feedback);
btnSendFeedback.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
final Handler handler2 = new Handler();
handler2.postDelayed(new Runnable() {
@Override
public void run() {
Intent userFeedbackIntent = new Intent();
userFeedbackIntent.setAction(Intent.ACTION_SEND_MULTIPLE);
userFeedbackIntent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, userResponseUri);
userFeedbackIntent.setType("message/rfc822");
userFeedbackIntent.putExtra(Intent.EXTRA_EMAIL, new String[]{"[email protected]"});
startActivity(userFeedbackIntent);
}
}, 200);
}
});
I first captured the text written in EditText
& then converted into Uri
to do the same as given here: http://developer.android.com/training/sharing/send.html
The problem which I'm encountering now is that when I click on btnSendFeedback
and choose Gmail, it says 'Couldn't attach file'.
As I'm a beginner, I'm unable to figure out what am I doing wrong.
Please let me know & if there is some another good way to accomplish this task then please tell about that.
Sorry for bad question formatting.
Thanks.
Ok, seems like you are using Intent.EXTRA_STREAM
which involves a 'file', and you don't have any file, don't you? (check this answer: Android: Intent.ACTION_SEND with EXTRA_STREAM doesn't attach any image when choosing Gmail app on htc Hero), So you can create a txt file and then try to attach it to your email.
Other option can be just fill the body of your email (check: Send Email Intent ) with the data that you want to send.
And if you want to avoid other app in the procces you can check this so answer: Sending email in android using javamail api without using the default built in app