22
votes

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 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..

4
Once you know the text that you want to share , you can use the shareACtion to directly share on messenger and messenger will let you decide which person to send this text to . - Kiloreux
Checkout gist.github.com/gelldur/9c199654c91b13478979 You can share by Messanger - Dawid Drozd
Well that is on iOS bro... - Boldijar Paul

4 Answers

39
votes

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();
    }
19
votes

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

3
votes

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
votes

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);