Android : Send feedback to default email [duplicate] - android

This question already has answers here:
Sending Email in Android using JavaMail API without using the default/built-in app
(25 answers)
Closed 6 years ago.
I've a feedback form and buttons for send and cancel. How can I make the feedback send responds to a default email when the send button is clicked? And how can I set a the default email. Is this possible? Please let me know. Thank you.
Here's is my java for the feedback form :
#Override
public void onClick(View arg0) {
// Create custom dialog object
final Dialog dialog = new Dialog(MainActivity.this);
// Include dialog.xml file
dialog.setContentView(R.layout.activity_main);
// Set dialog title
dialog.setTitle("Feedback");
dialog.show();
Button button1 = (Button) dialog.findViewById(R.id.button1);
// if decline button is clicked, close the custom dialog
button1.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
// Close dialog
dialog.dismiss();
}
});
Button button2 = (Button) dialog.findViewById(R.id.button2);
// if decline button is clicked, close the custom dialog
button2.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
// Close dialog
dialog.dismiss();
}
});

Open your email client programatically using a chooser:
Intent intent = new Intent(Intent.ACTION_SEND);
intent.setType("plain/text");
intent.putExtra(Intent.EXTRA_EMAIL, new String[] { "some#email.address" });
intent.putExtra(Intent.EXTRA_SUBJECT, "subject");
intent.putExtra(Intent.EXTRA_TEXT, "mail body");
startActivity(Intent.createChooser(intent, ""));
To send email programatically without using chooser,you can use this link.

You can use following snippet:
private void sendEmail(String email) {
Intent emailIntent = new Intent(Intent.ACTION_SENDTO);
String aEmailList[] = {email};
emailIntent.setData(Uri.parse("mailto:")); // only email apps should handle this
emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, aEmailList);
String feedback_msg = getString(R.string.feedback_msg);
emailIntent.putExtra(Intent.EXTRA_TEXT, Html.fromHtml("<i><font color='your color'>" + feedback_msg + "</font></i>"));
emailIntent.putExtra(Intent.EXTRA_SUBJECT, getString(R.string.feedback_msg));
PackageManager packageManager = getActivity().getPackageManager();
boolean isIntentSafe = emailIntent.resolveActivity(packageManager) != null;
if (isIntentSafe) {
startActivity(emailIntent);
} else {
Toast.makeText(getActivity(), R.string.email_app_not_installed, Toast.LENGTH_SHORT).show();
}
}
}

Related

How to implement email intent correctly

I searched stack overflow and the google documentation for email intents and found that code to be the go to code:
However, everytime I click "submit" in my activity I choose gmail. It opens a new email in gmail, but it only puts the receipient address. The subject and the text(name, email address and feedback text) are missing.
public void composeEmail(String[] addresses, String subject) {
Intent intent = new Intent(Intent.ACTION_SENDTO);
intent.setData(Uri.parse("mailto:")); // only email apps should handle this
intent.putExtra(Intent.EXTRA_EMAIL, addresses);
intent.putExtra(Intent.EXTRA_SUBJECT, subject);
if (intent.resolveActivity(getPackageManager()) != null) {
startActivity(intent);
}
}
I implemented that as the following code. Everything after the else is to have a AlertDialog pop up if there is no app installed.
public class EmailActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.acitvity_email);
final EditText nameField = (EditText) findViewById(R.id.editTextName);
final EditText addressField = (EditText) findViewById(R.id.editTextEmail);
final EditText subjectField = (EditText) findViewById(R.id.editTextSubject);
final EditText feedbackField = (EditText) findViewById(R.id.editTextFeedback);
final Button submitFeedback = (Button) findViewById(R.id.buttonSubmitFeedback);
final String name = nameField.getText().toString();
final String address = addressField.getText().toString();
final String subject = subjectField.getText().toString();
final String feedback = feedbackField.getText().toString().concat(name).concat(address);
submitFeedback.setOnClickListener(new View.OnClickListener(){
#Override
public void onClick(View v) {
composeFeedback(subject, feedback);
}
});
}
public void composeFeedback(String subject, String feedback){
Intent intent = new Intent(Intent.ACTION_SENDTO);
intent.setData(Uri.parse("mailto:" + "mydeveloperemail#gmail.com"));
intent.putExtra(Intent.EXTRA_TEXT,feedback);
intent.putExtra(Intent.EXTRA_SUBJECT, subject);
if (intent.resolveActivity(getPackageManager()) != null) {
startActivity(intent);
} else {
final Drawable fail = getResources().getDrawable(R.drawable.ic_fail);
AlertDialog.Builder builder = new AlertDialog.Builder(EmailActivity.this);
builder.setTitle("Fehler");
builder.setIcon(fail);
builder.setMessage("Keine Email App verfügbar!");
builder.setCancelable(false);
builder.setNeutralButton("Okay", new DialogInterface.OnClickListener(){
#Override
public void onClick(DialogInterface dialog, int which) {
dialog.cancel();
}
});
AlertDialog alert = builder.create();
alert.show();
}
}
Edit: deleted intent filter as #CommonsWare pointed out in his answer
ACTION_SENDTO is not required to use any extras. Put your data in the mailto: Uri, the way a Web page would.
In the android manifest i declared an intent filter to the activtiy
Unless you are writing an email app, like Gmail, this <intent-filter> is both unnecessary and damaging to users.

Get an Image uploaded on an Image view and send it

I have an image already chosen and in an image view but now I would like to send the same image using a send button.How can I fetch the image so that if one clicks on the send button it choses the image and gives him a variety of options in how he can send the image.
Send button code is below
Button buttonSendImage = (Button) findViewById(R.id.button2);
buttonSendImage.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
Intent picMessageIntent = new Intent(android.content.Intent.ACTION_SEND);
picMessageIntent.setType("image/jpeg");
startActivity(Intent.createChooser(picMessageIntent, "Send your picture using:"));
}
});Button buttonSendImage = (Button) findViewById(R.id.button2);
buttonSendImage.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
Intent picMessageIntent = new Intent(android.content.Intent.ACTION_SEND);
picMessageIntent.setType("image/jpeg");
startActivity(Intent.createChooser(picMessageIntent, "Send your picture using:"));
}
});
if my understanding is correct, You can use the following code :
Intent shareIntent = new Intent();
shareIntent.setAction(Intent.ACTION_SEND);
// Add your image URI here and send in a button click.
shareIntent.putExtra(Intent.EXTRA_STREAM, uriToImage);
shareIntent.setType("image/jpeg");
startActivity(Intent.createChooser(shareIntent, getResources().getText(R.string.send_to)));
You can use a MIME type of "*/*"

How to send Zip file from sdcard to mail in android

Hi friends,
I need to send zip file as attachment to email. I have tried using code below. However, I receive email message without the attachment. What am I doing wrong?
public class MainActivity extends Activity {
Button email;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
email=(Button)findViewById(R.id.button1);
email.setOnClickListener(new OnClickListener() {
public void onClick(View arg0) {
// TODO Auto-generated method stub
Intent intent = new Intent(Intent.ACTION_SEND);
intent.putExtra(Intent.EXTRA_EMAIL, new String[]{"radha#impressol.com"});
intent.putExtra(Intent.EXTRA_SUBJECT, "Email Subject");
intent.putExtra(Intent.EXTRA_TEXT, "Email Message");
intent.setType("application/zip");
intent.putExtra(Intent.EXTRA_STREAM, Uri.parse("file://+/sdcard/zipname.zip"));
startActivity(Intent.createChooser(intent, "Send Email"));
}
});
}
}
In your case remove the "+" from Uri string.
P.S. it'll also work without Uri protocol, like (Environment.getExternalStorageDirectory()+"/zipname.zip");

Can't add email signature in Android

I'm trying to compose and send an email which will include a signature at the bottom
of my email content in android. I'm able to send an email but I'm not getting the way that allows me to add my own signature. Do you have any suggestion?
here's my code:
public void addListener() {
final Button button = (Button) findViewById(R.id.button1);
button.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
findViewById = (TextView) findViewById(R.id.t1);
Intent i = new Intent(Intent.ACTION_SEND);
i.setType("text/plain");
i.putExtra(Intent.EXTRA_EMAIL,
new String[] { "some#gmail.com"});
/*i.putExtra(Intent.EXTRA_CC,
new String[] { "some#gmail.com" });*/
i.putExtra(Intent.EXTRA_SUBJECT, "Android Test");
i.putExtra(Intent.EXTRA_TEXT, "Body");
//i.putExtra(Intent.EXTRA_TEXT, "signature");
try {
startActivity(Intent.createChooser(i, "Choose mail app..."));
} catch (android.content.ActivityNotFoundException ex) {
}
}
});
}
I don't think the "signature" is really a different section of an email. I think you can just append your signature to your body.
i.putExtra(Intent.EXTRA_TEXT, "Body" + "\\n" + "Signature");

sending email in android

public class AndroidEmailActivity extends Activity {
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
final EditText edittextEmailAddress = (EditText) findViewById(R.id.email_address);
final EditText edittextEmailSubject = (EditText) findViewById(R.id.email_subject);
final EditText edittextEmailText = (EditText) findViewById(R.id.email_text);
Button buttonSendEmail_intent = (Button) findViewById(R.id.sendemail_intent);
buttonSendEmail_intent.setOnClickListener(new Button.OnClickListener() {
#Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
String emailAddress = edittextEmailAddress.getText().toString();
String emailSubject = edittextEmailSubject.getText().toString();
String emailText = edittextEmailText.getText().toString();
String emailAddressList[] = { emailAddress };
Intent intent = new Intent(Intent.ACTION_SEND);
intent.setType("plain/text");
intent.putExtra(Intent.EXTRA_EMAIL, emailAddressList);
intent.putExtra(Intent.EXTRA_SUBJECT, emailSubject);
intent.putExtra(Intent.EXTRA_TEXT, emailText);
startActivity(Intent.createChooser(intent,
"Choice App t send email:"));
}
});
}
}
This is my code.I am not getting any emails.I need to send emails through this intent method.how can I acheive that?Where I went wrong?pls give some suggestions.
I am getting the error when I click the Send email button as "No applications can perform this action."
This is my code to send emails:
Intent sendIntent = new Intent(Intent.ACTION_SEND);
sendIntent.putExtra(Intent.EXTRA_SUBJECT, activity.getString(R.string.share_email_subject));
sendIntent.setType("message/rfc822");
activity.startActivity(Intent.createChooser(sendIntent, "Choose Email Client"));
Try removing the plain/text type?
It is Good practice to work with original device rather than on Virtual Device. I suggest you try this code block on real device.
Intent sendEmail= new Intent(Intent.ACTION_SEND);
sendEmail.setType("plain/text");
startActivity(Intent.createChooser(sendEmail, "Email:"));
If you want to see more on Email with Intent then refer to this post:
http://androidtutforbeginner.blogspot.com/2012/03/send-email-with-intent-in-android.html

Categories

Resources