简体   繁体   English

如何向 facebook 发送消息

[英]How to send message to facebook

String url  ="https://m.facebook.com/messages/read/?fbid=101631428274763";
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
startActivity(intent);

I want to directly send some messages.我想直接发送一些消息。 This way I am able to send message to fb page...but, not able to add some texts to text field.这样我就可以将消息发送到 fb 页面......但是,无法在文本字段中添加一些文本。 So, how can I send messages?那么,我该如何发送消息呢? I know that I can do that by intent.putExtra but, what the name would be?我知道我可以通过intent.putExtra做到这一点,但是, name是什么?

Here is You sent a message direct to FB messenger.这是您直接向 FB messenger 发送的消息。

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

Following source code worked properly for me以下源代码对我来说正常工作

Uri uri = Uri.parse("fb-messenger://user/101631428274763");

    Intent toMessenger= new Intent(Intent.ACTION_VIEW, uri);
    toMessenger.putExtra(Intent.EXTRA_TEXT, "My message to send");
    try {
        startActivity(toMessenger);
    }
    catch (android.content.ActivityNotFoundException ex)
    {
        Toast.makeText(this, "Please Install Facebook Messenger",    Toast.LENGTH_LONG).show();
    }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM