user1483208
user1483208

Reputation: 385

Sending message by FB messenger

Since few days sending text by intent to facebook messenger is not working, I've tried several approaches: first:

        Intent sendIntent = new Intent();
    sendIntent.setAction(Intent.ACTION_SEND);
    sendIntent.putExtra(Intent.EXTRA_TEXT, getString(R.string.messenger_text));
    sendIntent.setType("text/plain");
    sendIntent.setPackage("com.facebook.orca");

second (based on facebook docs):

  Intent intent = new Intent(Intent.ACTION_SEND);
        intent.setPackage("com.facebook.orca");
        intent.setType("text/plain");
        intent.putExtra(Intent.EXTRA_STREAM, getString(R.string.messenger_text));
        intent.putExtra(EXTRA_PROTOCOL_VERSION, PROTOCOL_VERSION);
        intent.putExtra(EXTRA_APP_ID, YOUR_APP_ID);

Anyone have working example? I think this is new problem realted to last facebook messenger api update.

Upvotes: 2

Views: 3142

Answers (2)

This is working for me :

    Intent sendIntent = new Intent();
    sendIntent.setAction(Intent.ACTION_SEND);
    sendIntent.putExtra(Intent.EXTRA_TEXT, "My message to send");
    sendIntent.setType("text/plain");
    sendIntent.setPackage("com.facebook.orca");

    try {
        startActivity(sendIntent);
    } catch (android.content.ActivityNotFoundException ex) {
        ToastHelper.show(this, "Please Install Facebook Messenger");
    }

Upvotes: 4

user1483208
user1483208

Reputation: 385

Here is working solution with new API:

if (MessageDialog.canShow(ShareLinkContent.class)) {
                ShareLinkContent linkContent = new ShareLinkContent.Builder()
                        .setContentTitle("TITLE")
                        .setContentDescription("Desc")
                        .setContentUrl(Uri.parse("http://url"))
                        .build();

                messageDialog.show(linkContent);
            } else {
                showInfoDialog(getString(R.string.info_dialog_messenger_not_found));
            }

Upvotes: 1

Related Questions