Android Share Intent选择器 - 与Facebook/Twitter共享文本社交媒体等

tip*_*jat 6 java android facebook android-intent

如果我只发送文本,Share Intent选择器不会将Facebook/Twitter作为选项.

只有Gmail,Skype和Evernote可供选择.

这是我的代码

Intent shareIntent = new Intent(Intent.ACTION_SEND);

shareIntent.setType("plain/text");
shareIntent.putExtra(Intent.EXTRA_TEXT, text)
startActivity(Intent.createChooser(shareIntent, "Share using"));
Run Code Online (Sandbox Code Playgroud)

我尝试了不同的setType()组合,包括"text/*","text/html",并在putExtra中传递HTML文本,如下所示:

shareIntent.putExtra(Intent.EXTRA_TEXT, Html.fromHtml("<p>This is the text that will be shared.</p>"));
Run Code Online (Sandbox Code Playgroud)

当我使用"text/plain"时,Facebook会出现一个选项,但选择它时文本不会加载.但该文本确实加载了Twitter,电子邮件,短信.

还有其他人遇到过这个问题吗?

当我分享图像时,没有问题,Facebook和其他社交媒体应用程序在列表中可用.

ped*_*oso 7

根据文档,它也应该是"text/plain"而不是"plain/text".


Orl*_*mee 3

这取决于每个应用程序定义的意图过滤器。
例如,如果我添加意图过滤器 android.intent.action.send

如果我从图库中选择单个图像,我的应用程序将出现在列表中。但是,如果我选择多个,我的应用程序将不会出现,因为我还没有添加意图文件管理器android.intent.action.send_multiple

所以这取决于 Facebook 过滤的意图。您需要查看发行说明或帮助或开发人员页面。