Android 与 Facebook Messenger 共享文本?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/26101675/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Share a text with facebook messenger?
提问by Boldijar Paul
Is there a way to share a text in facebook messenger using android and maybe facebook sdk as well?
有没有办法使用android和facebook sdk在facebook Messenger中共享文本?
I want to make something like the whatsapp way, choose your text and open an intent to choose the guy you want to send to... Is there a way to do this with facebook messenger? It appears in the intent.choose dialog..but I only want to send to facebook messenger..
我想做一些类似 whatsapp 的方式,选择你的文本并打开一个意图来选择你想要发送给的人......有没有办法用 Facebook Messenger 做到这一点?它出现在 intent.choose 对话框中..但我只想发送到 Facebook Messenger..
回答by Dhinakaran Thennarasu
use this code onClick,,
使用此代码 onClick,,
com.facebook.orca is the package name for fb messenger.
com.facebook.orca 是 fb messenger 的包名。
Intent sendIntent = new Intent();
sendIntent.setAction(Intent.ACTION_SEND);
sendIntent
.putExtra(Intent.EXTRA_TEXT,
"<---YOUR TEXT HERE--->.");
sendIntent.setType("text/plain");
sendIntent.setPackage("com.facebook.orca");
try {
startActivity(sendIntent);
}
catch (android.content.ActivityNotFoundException ex) {
Toast.makeText(context,"Please Install Facebook Messenger", Toast.LENGTH_LONG).show();
}
回答by Ninad Kambli
to start Facebook messenger with a particular user
使用特定用户启动 Facebook 信使
Uri uri = Uri.parse("fb-messenger://user/");
uri = ContentUris.withAppendedId(uri,[provide user id]);
Intent intent = new Intent(Intent.ACTION_VIEW, uri);
startActivity(intent);
Uri uri = Uri.parse("fb-messenger://user/");
uri = ContentUris.withAppendedId(uri,[provide user id]);
Intent intent = new Intent(Intent.ACTION_VIEW, uri);
startActivity(intent);
it will start the messenger for user id you mention
它将为您提到的用户 ID 启动 Messenger
回答by yrizk
alternatively, you can use their messenger sdk (https://developers.facebook.com/docs/messenger/android) and that will pop up a screen where you can select one or many users to send the message to. Only catch is you can't prefill the text , but you can attach rich media.
或者,您可以使用他们的 messenger sdk ( https://developers.facebook.com/docs/messenger/android),这将弹出一个屏幕,您可以在其中选择一个或多个用户来发送消息。唯一的问题是您不能预填充 text ,但您可以附加富媒体。
回答by Lait
only link/video/picture
只有链接/视频/图片
And here's the bad news: https://developers.facebook.com/docs/messenger-platform/changelog/?locale=en_US#20190610
这是坏消息:https: //developers.facebook.com/docs/messenger-platform/changelog/?locale=en_US#20190610
June 10, 2019
Messenger Platform Announcement
Won't function with the new app
Share to Messenger SDKthat allows people to share links and media from apps to Messenger will no longer be supported. Businesses and developers might need to make modifications to their app to trigger native OS sharing. People will be able to share content to Messenger using the native sharing features that is built into their devices.
2019 年 6 月 10 日
Messenger 平台公告
不适用于新应用
将不再支持共享到 Messenger SDK,该SDK允许人们将链接和媒体从应用程序共享到 Messenger。企业和开发人员可能需要修改他们的应用程序以触发本机操作系统共享。人们将能够使用设备内置的本机共享功能向 Messenger 共享内容。
but in my test on Android,I can still share the link/pic/video to Messenger using the latest Facebook SDK
但是在我在 Android 上的测试中,我仍然可以使用最新的 Facebook SDK 将链接/图片/视频共享到 Messenger
import com.facebook.share.model.ShareLinkContent;
import com.facebook.share.widget.MessageDialog;
ShareLinkContent content = new ShareLinkContent.Builder()
.setContentUrl(Uri.parse("https://xxx.xxx/xxx"))
.build();
//no callback
MessageDialog.show(context, content);