Share a text with facebook messenger?
Asked Answered
N

4

24

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

Neves answered 29/9, 2014 at 13:58 Comment(3)
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 .Sayles
Checkout gist.github.com/gelldur/9c199654c91b13478979 You can share by MessangerArchi
Well that is on iOS bro...Neves
E
41

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();
    }
Exegetic answered 29/9, 2014 at 14:7 Comment(6)
@WizKid we can do this on Android but not ios, cant we ? Why fb does not let ios to send text over Messenger ?Epilogue
Beginning early May 2015 Messenger no longer register itself as share intent target. Until it changes, code above won't work.Dope
Thanks Tomash.. unfortunate.. will update the same.!Exegetic
Message sharing (code above) is working when I tried on 1 November 2015 using facebook-android-sdk-4.5.0.Gargantuan
Messenger shows up in the default system sharing picker when you share text in chrome, so it must've been added back.Shallop
August 2017, Facebook SDK 4.23.0, Messenger intent working with no issues.Bomber
E
19

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

Ecosystem answered 15/4, 2015 at 13:13 Comment(7)
@Ninad Kambli dear pls explore the user id,how i will open specific user tanxAirboat
user id is the one that you get when tou make a request to api of facebook i.e. "v1.0/me/friends" and get the idEcosystem
this opens the messenger window but nothing is getting loaded. am i missing something?Corneous
Worked for me! Thank you very much @NinadKambliUziel
this is not opening the exact user.Thorite
Writing in January 2018, This does not work anymore.Bounty
This will crash, if user doesn't have Facebook Messenger on the device.Cykana
B
3

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.

Barometrograph answered 11/11, 2015 at 22:55 Comment(0)
M
0

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);
Micah answered 3/5, 2020 at 3:5 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.