Warm tip: This article is reproduced from stackoverflow.com, please click
android whatsapp

Sending Document and Text both in WhatsApp

发布于 2020-04-03 23:20:54

Currently, I wanted to send app generated PDF or Excel file from WhatsApp with text. But after opening chat screen only file getting sends and not a text. Same code working for email client where text gets added as a body

Intent intentShareFile = new Intent(Intent.ACTION_SEND);

    intentShareFile.putExtra(Intent.EXTRA_SUBJECT,
            "My Subject");//Only used if user selects email client

    intentShareFile.putExtra(Intent.EXTRA_TEXT,
            "Extra text");

    if (isReportInPDF())
        intentShareFile.setType("application/pdf");
    else
        intentShareFile.setType("application/vnd.ms-excel");

    intentShareFile.putExtra(Intent.EXTRA_STREAM, Uri.parse("file://" + url));

    startActivity(Intent.createChooser(intentShareFile, "Share File"));
Questioner
P Vartak
Viewed
30
P Vartak 2020-01-31 19:22

If you supply both extras, it is up to the consuming app to decide what to do with them and not all apps will use both.

As Per this comment.