Share a text with facebook messenger?

后端 未结 4 1397
囚心锁ツ
囚心锁ツ 2020-12-10 11:05

Is there a way to share a text in facebook messenger using android and maybe facebook sdk as well?

I want to make something like the whatsapp way, choose your text a

相关标签:
4条回答
  • 2020-12-10 11:31

    to start Facebook messenger with a particular user

    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

    0 讨论(0)
  • 2020-12-10 11:32

    use this code onClick,,

    com.facebook.orca is the package name for 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();
        }
    
    0 讨论(0)
  • 2020-12-10 11:48

    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.

    0 讨论(0)
  • 2020-12-10 11:54

    only link/video/picture

    https://developers.facebook.com/docs/sharing/android/

    And here's the bad news: 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 SDK that 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.

    but in my test on Android,I can still share the link/pic/video to Messenger using the latest Facebook SDK

    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);
    
    0 讨论(0)
提交回复
热议问题