Android共享主题电子邮件/Whatsapp

Android共享主题电子邮件/Whatsapp,android,email,whatsapp,android-sharing,Android,Email,Whatsapp,Android Sharing,我正在使用android本机共享,代码如下: Intent intent = new Intent(Intent.ACTION_SEND); intent.putExtra(Intent.EXTRA_TEXT, "I like to share with you some stuff."); intent.putExtra(Intent.EXTRA_SUBJECT, "I like to share with you."); intent.setType(CONTENT_TYPE_TEXT);

我正在使用android本机共享,代码如下:

Intent intent = new Intent(Intent.ACTION_SEND);
intent.putExtra(Intent.EXTRA_TEXT, "I like to share with you some stuff.");
intent.putExtra(Intent.EXTRA_SUBJECT, "I like to share with you.");
intent.setType(CONTENT_TYPE_TEXT);
startActivity(Intent.createChooser(intent, "Share");
当我使用电子邮件作为共享渠道时,我得到了我想要的:

Subject: I like to share with you.
Text:    I like to share with you some stuff.
当我使用WhatsApp作为共享频道时,我得到以下文本:

I like to share with you.

I like to share with you some stuff.
与Whatsapp共享时,我期望得到什么:

I like to share with you some stuff.
如果共享频道基本上不支持主题,是否有任何选项/标志指示共享频道抑制主题

例如,电子邮件支持主题->使用提供的额外意图。
WhatsApp不支持主题->不要使用提供的intent extra。

使用
PackageManager
类的
queryIntentActivities()
方法,可以根据包名设置intent extras

有关更多信息,请查看此链接:

使用以下代码(考虑到我们正在活动中使用该功能),如果所选应用程序是电子邮件,它将具有主题,否则主题部分将无法用于其他应用程序,如messenger、SMS或文本。Body(setText)将以相同的方式用于所有应用程序

                ShareCompat.IntentBuilder.from(this)
                    .setSubject("I like to share with you.")
                    .setChooserTitle("Share")
                    .setType("text/plain")
                    .setText("I like to share with you some stuff.")
                    .startChooser()