5

我正在使用带有此代码的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 不支持主题 -> 不要额外使用提供的意图。

4

2 回答 2

2

使用类queryIntentActivities()的方法PackageManager,您可以根据包名称设置意图附加项。

有关更多信息,请查看此链接:如何为 ACTION_SEND 意图过滤特定应用(并为每个应用设置不同的文本)

于 2015-02-19T11:46:22.787 回答
0

使用下面的代码(考虑我们在活动中使用该功能),如果所选应用程序是电子邮件,它将有一个主题,否则主题部分将不适用于其他应用程序,如信使、短信或文本。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()
于 2021-01-25T12:29:55.033 回答