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
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 am adding share feature in the app. Below is my code:
public static void shareData(String title, String message, Uri imageUri, Activity activity) {
try {
Intent sendIntent = new Intent(Intent.ACTION_SEND);
sendIntent.putExtra(Intent.EXTRA_TITLE, title);
sendIntent.putExtra(Intent.EXTRA_SUBJECT, message);
if (imageUri != null) {
Logger.errorMessage(ShareUtil.class.getSimpleName(), "share if");
sendIntent.putExtra(Intent.EXTRA_STREAM, imageUri);
sendIntent.setType("image/*");
} else {
Logger.errorMessage(ShareUtil.class.getSimpleName(), "share else");
sendIntent.setType("text/plain");
}
activity.startActivity(Intent.createChooser(sendIntent, "Share using"));
} catch (Exception e) {
e.printStackTrace();
Toast.makeText(activity, "No App found to share", Toast.LENGTH_LONG).show();
}
}
This is showing the list of apps, but when I select any app, the title and message is not sent. I am not getting what I am doing wrong.
Intent.EXTRA_SUBJECT is mainly used in email. Try replacing it with Intent.EXTRA_TEXT. This works in most apps.
Is it Possible to send whatsapp from the number stored in database(SQLite)
SO Far I have tried sending a whatsapp from older post but its sending ony msgs or opening only contacts when i am combining both I am not getting any result
//This Will Open Specific Contact on Whatsapp
void openWhatsappContact() {
String number = "919033152265";
Uri uri = Uri.parse("smsto:" + number);
Intent i = new Intent(Intent.ACTION_SENDTO, uri);
i.setPackage("com.whatsapp");
startActivity(Intent.createChooser(i, ""));
}
//This Will Send Specific Msg to WhatsAPP
public void SelectContactAndMsgSend(View view) {
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();
}
}
//Combining Both Not getting Any result
public void CombiningBoth(View view) {
String number = "Here GOes My Number"; //As i am from india my number Im putting is 91xxxxxxxxxx
Uri uri = Uri.parse("smsto:" + number);
Intent waIntent = new Intent(Intent.ACTION_SENDTO, uri);
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, ""));
} else {
Toast.makeText(this, "WhatsApp not Installed", Toast.LENGTH_SHORT)
.show();
}
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;
Is it possible to make an imageview link to the email app? Like when you click it the email app will open with a specific email address to send?
findViewById(R.id.imageview).setOnClickListener(new OnClickListener() {
public void onClick(View _) {
Intent i = new Intent(Intent.ACTION_VIEW);
i.setData(Uri.fromParts("mailto","abc#gmail.com", null));
startActivity(i);
}
}
img.setOnClickListener(
new OnClickListener(View v) {
String yourMail = "mail#example.com";
Intent intent = new Intent(Intent.ACTION_SEND);
intent.setType("message/rfc822");
intent.putExtra(Intent.EXTRA_EMAIL, new String[]{yourMail});
intent.putExtra(Intent.EXTRA_SUBJECT, "Your subject");
intent.putExtra(Intent.EXTRA_TEXT, "Your content");
try {
startActivity(intent, "Pick an email application...");
} catch(Exception e) {
Toast.makeText(YourMainActivity.this, "Have no email application!", Toast.LENGTH_SHORT).show();
}
}
);