首页 > 解决方案 > 标题和正文 - android 应用程序中的意图 Action_SEND

问题描述

所以,我试图通过 Viber、Whatsapp 等社交应用程序分享我文章的标题和文本。所以,下面是我的代码,问题是它只共享正文,而不是标题。但它会读取它,正如您在共享对话框中看到的那样(它是具有较大字体的文本)。但正如您在第二张截图中看到的那样,它只传递了正文。这里有什么问题?

http://prntscr.com/urd4z6 http://prntscr.com/urd57q

holder.imgShareM.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {


                        String s1 = holder.txt_short_desc.getText().toString();
                        String s2 = holder.txt_description.getText().toString();
                        Intent sharingIntent = new Intent();
                        sharingIntent.setAction(Intent.ACTION_SEND);
                        sharingIntent.setType("text/plain");
                        sharingIntent.putExtra(android.content.Intent.EXTRA_TITLE, s1);
                        sharingIntent.putExtra(android.content.Intent.EXTRA_TEXT, s2);
                        activity.startActivity(Intent.createChooser(sharingIntent, "Share the article via:"));

 }
            });

编辑:一点更新。我尝试通过以下方式在底部添加我的应用程序链接:

sendIntent.putExtra(Intent.EXTRA_TEXT, getString(R.string.sharing_text) + "\n" +
                        "https://play.google.com/store/apps/details?id=" + getPackageName());

现在它只发送那个。所以,它似乎只发送最后一件事。

标签: javaandroidandroid-intent

解决方案


您应该使用此行将标题添加到您的电子邮件:

intent.putExtra(Intent.EXTRA_SUBJECT, "Your Subject Here");

推荐阅读