在 WhatsApp 中发送文档和文本

Sending Document and Text both in WhatsApp

目前,我想从 WhatsApp 发送带有文本的应用程序生成的 PDF 或 Excel 文件。但是在打开聊天屏幕后,只有文件被发送而不是文本。 相同的代码适用于电子邮件客户端,其中文本被添加为正文

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"));

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.

根据 评论。