Android. Send text to facebook messenger by Facebo

2019-02-17 15:20发布

问题:

As document from facebook, we can send image from android app to facebook messenger like below.

String metadata = "{ \"image\" : \"trees\" }";
ShareToMessengerParams shareToMessengerParams =
    ShareToMessengerParams.newBuilder(contentUri, "image/jpeg")
            .setMetaData(metadata)
            .build();

// Sharing from an Activity
MessengerUtils.shareToMessenger(this, 0, shareToMessengerParams);

But I want to send just text. So I tried below.

ShareToMessengerParams shareToMessengerParams =
    ShareToMessengerParams.newBuilder(null, "text/plain")
            .setMetaData("text to send")
            .build();

// Sharing from an Activity
MessengerUtils.shareToMessenger(this, 0, shareToMessengerParams);

When I tested this, java.lang.NullPointerException: Must provide non-null uri exception occurs.

How can I send message to facebook messenger..? Using Intent is not available now, so I need to use facebook sdk 4.X.

回答1:

Here is the Facebook Documentation

Facebook (and Messenger) doesn't not allow sharing text only.