繁体   English   中英

如何共享文本和从Android应用程序到Messenger的链接?

[英]How to share text and link from android app to messenger?

我希望有可能共享一些文本和从我的应用程序到Messenger的链接,并获得如下消息:(从Elephant Evolution应用程序共享的消息)

从Elephant Evolution应用分享的消息

这是我的代码:

                //SHARING TO FACEBOOK
            String photoURL = "https://play.google.com/";
            if(!mEvent.getPhotoUrl().isEmpty()){
                photoURL=mEvent.getPhotoUrl();
            }
            String quoteToShare = "someText";
            ShareLinkContent content = new ShareLinkContent.Builder()
                    .setContentUrl(Uri.parse(photoURL))
                    .setQuote(quoteToShare)
                    .build();
            //ShareDialog.show(EventActivity.this,content);
            MessageDialog.show(EventActivity.this, content);

并使用此代码,我只共享链接:

在此处输入图片说明

当我与Facebook共享相同的“ ShareLinkContent”时,一切正常。 谁能帮助我:)?

您可以使用Intent类共享文本(和链接):

import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.widget.Button;

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        Button button = findViewById(R.id.button);
        String textToShare = "My own text\nhttps://stackoverflow.com/";

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

        button.setOnClickListener(v -> {
            try {
                startActivity(sendIntent);
            } catch (Exception ex) {
                ex.printStackTrace();
            }
        });
    }
}

Facebook Messenger的软件包是: com.facebook.orca

暂无
暂无

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

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