I have an app which gathers user data, and displays them into a listview. I also have an EmailSender class with the following function;
protected void sendEmail() {
Log.i("Send email", "");
String[] TO = {"amrood.admin#gmail.com"};
String[] CC = {"mcmohd#gmail.com"};
Intent emailIntent = new Intent(Intent.ACTION_SEND);
emailIntent.setData(Uri.parse("mailto:"));
emailIntent.setType("text/plain");
emailIntent.putExtra(Intent.EXTRA_EMAIL, TO);
emailIntent.putExtra(Intent.EXTRA_CC, CC);
emailIntent.putExtra(Intent.EXTRA_SUBJECT, "Your subject");
emailIntent.putExtra(Intent.EXTRA_TEXT, "Email message goes here");
try {
startActivity(Intent.createChooser(emailIntent, "Send mail..."));
finish();
Log.i("Finished sending email...", "");
} catch (android.content.ActivityNotFoundException ex) {
Toast.makeText(MainActivity.this,
"There is no email client installed.", Toast.LENGTH_SHORT).show();
}
}
I want to automatically add the sqlite data into the email as an attachment. Any thoughts on that?
You can add the sqllite path as an extra like this
emailIntent.putExtra(android.content.Intent.EXTRA_STREAM, Uri.parse(sqllitePath));
sqlitePath should be built like
sqlitePath = "file://" + sqliteFolder.getAbsolutePath() + "/" + sqliteDbName;
Related
I would like to know how to open the Activity for composing email in gmail or outlook. By now I only know ho to be redirected to for instance gmail but I would also open the "composer" (or whatever) and add an email address. I've already tried with:
intent.putExtra(Intent.EXTRA_EMAIL , new String[]{"recipient#example.com"});
but doesnot work
full source to the test-app
public class MainActivity extends AppCompatActivity {
private static final String GOOGLE_MAIL = "com.google.android.gm";
private static final String OUTLOOK = "com.microsoft.office.outlook";
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
test(GOOGLE_MAIL);
}
private void test(String mail) {
Intent intent = getPackageManager().getLaunchIntentForPackage(mail);
intent.putExtra(Intent.EXTRA_EMAIL , new String[]{"recipient#example.com"});
startActivity(intent);
}
}
You can try this:
protected void sendEmail() {
Log.i("Send email", "");
String[] TO = {"someone#gmail.com"};
String[] CC = {"xyz#gmail.com"};
Intent emailIntent = new Intent(Intent.ACTION_SEND);
emailIntent.setData(Uri.parse("mailto:"));
emailIntent.setType("text/plain");
emailIntent.putExtra(Intent.EXTRA_EMAIL, TO);
emailIntent.putExtra(Intent.EXTRA_CC, CC);
emailIntent.putExtra(Intent.EXTRA_SUBJECT, "Your subject");
emailIntent.putExtra(Intent.EXTRA_TEXT, "Email message goes here");
try {
startActivity(Intent.createChooser(emailIntent, "Send mail..."));
finish();
Log.i("Finished sending email...", "");
} catch (android.content.ActivityNotFoundException ex) {
Toast.makeText(MainActivity.this,
"There is no email client installed.", Toast.LENGTH_SHORT).show();
}
}
I was trying to send an email with image as attachment.I see the item attached to the mail while sending , but in the inbox i see just the mail message but attachment missing. Please help me if my code went wrong somewhere
ArrayList<String> fetchList= new ArrayList<>();
fetchList= getIntent().getStringArrayListExtra("Uri");
ArrayList<Uri> uriList=new ArrayList<>();
for (int i=0;i<fetchList.size();i++){
uriList.add(i,Uri.parse(fetchList.get(i)));
}
public void sendClicked(View view) {
String emailBody =textMessage.getText().toString();
String emailSubject=textSubject.getText().toString();
String Email_To[]=new String[]{"kittutanu#yahoo.co.in"};
final Intent intent = new Intent(Intent.ACTION_SEND_MULTIPLE);
intent.setType("text/plain");
intent.putExtra(Intent.EXTRA_EMAIL, Email_To);
intent.putExtra(Intent.EXTRA_SUBJECT, emailSubject);
intent.putExtra(Intent.EXTRA_TEXT, emailBody);
if (uriList != null) {
intent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, uriList);
}
try {
this.startActivity(intent);
} catch (android.content.ActivityNotFoundException ex) {
Toast.makeText(this, "There are no email clients installed.", Toast.LENGTH_SHORT).show();
}
}
}
Have you tried with multipart/alternative or multipart/mixed type?
Here is an example How to send an email with a file attachment in Android
hello i am trying to send an email from an android application , the below code is working fine since it is opening the email app configured on the phone but the problem is it is not taking the subject and the Bcc any ideas
send.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
final Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
emailIntent.setType("plain/text");
emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, new String[]{ address.getText().toString()});
emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, subject.getText());
emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, emailBody.getText());
emailIntent.putExtra(android.content.Intent.EXTRA_BCC, CC.getText());
startActivity(Intent.createChooser(emailIntent, "Send mail..."));
}
});
As you can see in the getting the address you got the text by .getText(); then you made it a string for other uses, because it was an editable text from editText. But in the other EditTextss you forgot to add .toString(); so you can use it as a string in email.
try this:
send.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
final Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
emailIntent.setType("plain/text");
emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, new String[]{ address.getText().toString()});
emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, subject.getText().toString());
emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, emailBody.getText().toString());
emailIntent.putExtra(android.content.Intent.EXTRA_BCC, CC.getText().toString());
startActivity(Intent.createChooser(emailIntent, "Send mail..."));
}
});
please ask if you didn't understand
Try
send.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
final Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
emailIntent.setType("plain/text");
emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, new String[]{ address.getText().toString()});
emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, subject.getText().toString());
emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, emailBody.getText().toString());
emailIntent.putExtra(android.content.Intent.EXTRA_BCC, CC.getText().toString());
startActivity(Intent.createChooser(emailIntent, "Send mail..."));
}
});
EditText.getText() return a editable you need to change it to String by applying toString();
Will work 100%
String[] to = value.toString().split(",");
Intent i = new Intent(Intent.ACTION_SEND);
i.setType("text/html");
i.putExtra(Intent.EXTRA_EMAIL, to);
i.putExtra(Intent.EXTRA_BCC, "array of bcc like to");
i.putExtra(Intent.EXTRA_SUBJECT, String.format(getString(R.string.share_email_subject), IN_SHARE_CAPTION));
i.putExtra(
Intent.EXTRA_TEXT,
Html.fromHtml(IjoomerUtilities.prepareEmailBody(message == null ? "" : message, getSmartApplication().readSharedPreferences().getString(SP_USERNAME, "") + " " + getString(R.string.saw_this_story_on_the) + " "
+ getString(R.string.app_name) + " " + getString(R.string.thought_you_should_see_it), IN_SHARE_CAPTION, IN_SHARE_DESCRIPTION, IN_SHARE_SHARELINK, getString(R.string.try_ijoomeradvance), getString(R.string.site_url))));
try {
startActivity(Intent.createChooser(i, "Send mail..."));
finish();
} catch (android.content.ActivityNotFoundException ex) {
ting(getString(R.string.share_email_no_client));
}
This is how I am calling the SMS app:
Intent sendIntent = new Intent(Intent.ACTION_VIEW);
sendIntent.putExtra("sms_body", "The SMS text");
sendIntent.setType("vnd.android-dir/mms-sms");
startActivity(sendIntent);
How do I do the same for sending messages via twitter/Whatsapp/Facebook? What should I write in place of mms-sms? I found no documentation on such.
I can't also find any way of calling Facebook/Twitter directly, but you could always call android.content.Intent.ACTION_SEND and let the user choose the application.
Intent i = new Intent(android.content.Intent.ACTION_SEND);
i.setType("text/plain");
i.putExtra(Intent.EXTRA_SUBJECT, "Subject");
i.putExtra(Intent.EXTRA_TEXT, "Message body");
startActivity(Intent.createChooser(i, "Share dialog title"));
However, there might be a bug when using this to share through Facebook. For more information please see: Android Facebook Intent
public void onClickWhatsApp(View view) {
try {
Intent waIntent = new Intent(Intent.ACTION_SEND);
waIntent.setType("text/plain");
String text = "YOUR TEXT HERE";
waIntent.setPackage("com.whatsapp");
if (waIntent != null) {
waIntent.putExtra(Intent.EXTRA_TEXT, text);//
startActivity(Intent.createChooser(waIntent, "Share with"));
} else {
Toast.makeText(this, "WhatsApp not Installed", Toast.LENGTH_SHORT)
.show();
}} catch (NameNotFoundException e) {
Toast.makeText(this, "WhatsApp not Installed", Toast.LENGTH_SHORT)
.show();
}
}
Intent i = new Intent(Intent.ACTION_SEND);
i.setPackage("com.whatsapp");
i.putExtra("chat",true);
i.setType("text/plain");
startActivity(i);
You can use the following snippets:
For WhatsApp:
public void onClickWhatsApp(View view) {
PackageManager pm=getPackageManager();
try {
Intent waIntent = new Intent(Intent.ACTION_SEND);
waIntent.setType("text/plain");
String text = "YOUR TEXT HERE";
PackageInfo info=pm.getPackageInfo("com.whatsapp", PackageManager.GET_META_DATA);
//Check if package exists or not. If not then code
//in catch block will be called
waIntent.setPackage("com.whatsapp");
waIntent.putExtra(Intent.EXTRA_TEXT, text);
startActivity(Intent.createChooser(waIntent, "Share with"));
} catch (NameNotFoundException e) {
Toast.makeText(this, "WhatsApp not Installed", Toast.LENGTH_SHORT)
.show();
}
}
For Twitter:
void shareOnTwitter()
{
PackageManager pm=getPackageManager();
try {
Intent waIntent = new Intent(Intent.ACTION_SEND);
waIntent.setType("text/plain");
String text = "Insert Tweet Here";
#SuppressWarnings("unused")
PackageInfo info=pm.getPackageInfo("com.twitter.android", PackageManager.GET_META_DATA);
//Check if package exists or not. If not then code
//in catch block will be called
waIntent.setPackage("com.twitter.android");
waIntent.putExtra(Intent.EXTRA_TEXT, text);
startActivity(Intent.createChooser(waIntent, "Share with"));
} catch (NameNotFoundException e) {
Toast.makeText(this, "Twitter not Installed", Toast.LENGTH_SHORT)
.show();
return ;
}
return ;
}
In my application i want send a email to one account.in one button click event.i used the below code . this have exception
public void onClick(View v) {
sendEmail(context, new String[]{"jayampalaniraja#gmail.com"}, "Sending Email", "Test Email", "I am body");
}
private void sendEmail(Context context, String[] recipientList,
String subject, String body, String title) {
Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
emailIntent.setType("plain/text");
emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, recipientList);
emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, subject);
emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, body);
emailIntent.addFlags(Intent.FLAG_ACTIVITY_MULTIPLE_TASK);
try
{
context.startActivity(Intent.createChooser(emailIntent, title));
}catch(Exception e)
{
System.out.println(e);
}
}
The exception I am getting as
"03-19 19:13:19.553: I/System.out(2010): android.util.AndroidRuntimeException: Calling startActivity() from outside of an Activity context requires the FLAG_ACTIVITY_NEW_TASK flag.
Try this
private void sendEmail(Context context, String[] recipientList,
String subject, String body, String title) {
Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
emailIntent.setType("plain/text");
emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, recipientList);
emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, subject);
emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, body);
emailIntent.addFlags(Intent.FLAG_ACTIVITY_MULTIPLE_TASK);
emailIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
try
{
context.startActivity(Intent.createChooser(emailIntent, title));
}catch(Exception e)
{
System.out.println(e);
}
}
It's working fine. first thing to configure a email client for your emulator.enter code here
public void onClick(View v) {
// TODO Auto-generated method stub
Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
String aEmailList[] = { "pal#Yahoo.co.in" };
//String aEmailCCList[] = { ""};
//String aEmailBCCList[] = { "" };
emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, aEmailList);
//emailIntent.putExtra(android.content.Intent.EXTRA_CC, aEmailCCList);
//emailIntent.putExtra(android.content.Intent.EXTRA_BCC, aEmailBCCList);
emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, "My subject");
emailIntent.setType("message/rfc822");
emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, "My message body.");
try
{
startActivity(emailIntent);
}catch (android.content.ActivityNotFoundException ex) {
Toast.makeText(about.this, "There are no email clients installed.", Toast.LENGTH_SHORT).show();
}
catch(Exception e){ System.out.println(e);}
}