52

我之前使用过共享类型的意图,例如:

Intent intent = new Intent(Intent.ACTION_SEND);
intent.setType("plain/text");
intent.putExtra(Intent.EXTRA_EMAIL, new String[] { "---" });
intent.putExtra(Intent.EXTRA_SUBJECT, "---");
startActivity(Intent.createChooser(intent, "Contact Us!"));

但是,这基本上与电子邮件/彩信和其他文本或文档类型的应用程序共享。你如何做同样的事情,但包括 Facebook、Twitter 和 Google Plus 等社交分享(举出重要的名字)。我想分享的是这个应用程序,上面的文字说,“嘿,下载这个链接来看看这个应用程序!” (或类似的东西)。

4

7 回答 7

138

要添加 Facebook、Twitter 等共享选项,用户只需安装这些应用程序。这取决于其他应用程序Intents它们将告诉系统它们可以处理的类型。

然后一个基本的ACTION_SEND意图将被拾起。

Intent sendIntent = new Intent();
sendIntent.setAction(Intent.ACTION_SEND);
sendIntent.putExtra(Intent.EXTRA_TEXT,
    "Hey check out my app at: https://play.google.com/store/apps/details?id=" + BuildConfig.APPLICATION_ID);
sendIntent.setType("text/plain");
startActivity(sendIntent);

来源

于 2012-12-18T20:43:11.053 回答
19

如果您应用此代码,则如下图所示

Intent intent = new Intent(Intent.ACTION_SEND);
intent.setType("text/plain");
intent.putExtra(Intent.EXTRA_SUBJECT, "My application name");
intent.putExtra(Intent.EXTRA_TEXT, "This is my text");
startActivity(Intent.createChooser(intent, "choose one"));

在此处输入图像描述

==================================================== ====================

如果您应用此代码,则如下图所示

Intent sendIntent = new Intent(Intent.ACTION_SEND);
sendIntent.setType("text/plain");
sendIntent.putExtra(Intent.EXTRA_TEXT, "This is my text to send.");
startActivity(sendIntent);

在此处输入图像描述

于 2018-07-31T11:56:56.787 回答
6

您可以通过使用共享意图来做到这一点

            Intent shareIntent = new Intent(Intent.ACTION_SEND);
            shareIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            shareIntent.setType("text/plain");
            shareIntent.putExtra(android.content.Intent.EXTRA_TEXT, "Hey, download this app!");
            startActivity(shareIntent);     

您可以将此意图放在 onclick 中或在任何您想要的地方使用它

我认为这回答了你的问题=)

于 2012-12-18T20:43:02.533 回答
3

在 Kotlin 中,我们可以这样做:

 private fun share(messageToShare: String, appUrl: String) {
    val intent = Intent(Intent.ACTION_SEND)
    intent.type = "text/plain"
    intent.putExtra(Intent.EXTRA_TEXT, messageToShare + appUrl)
    startActivity(Intent(intent))
}
于 2020-07-31T13:20:42.157 回答
2

Intent.EXTRA_TEXT额外分享google play的链接

于 2012-12-18T20:43:41.513 回答
2

您还可以在共享应用程序时添加标题、主题和正文:

Intent sharingIntent = new Intent(android.content.Intent.ACTION_SEND);
                sharingIntent.setType("text/plain");
                sharingIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, "My App Name");
                sharingIntent.putExtra(android.content.Intent.EXTRA_TEXT, getResources().getString(R.string.share_app_text));
                startActivity(Intent.createChooser(sharingIntent, "Share app via"));
于 2018-06-14T11:08:51.640 回答
1

试试这对我来说工作正常:

 Intent intent = new Intent();
    intent.setAction(Intent.ACTION_SEND);
    intent.putExtra(Intent.EXTRA_TEXT,"I suggest this app for you : https://play.google.com/store/apps/details?id=com.android.chrome");
    intent.setType("text/plain");
    startActivity(intent);
于 2018-06-14T11:21:38.757 回答