在导航栏中共享,一切正常,但是在Whatsapp中,仅显示链接而不是文本

时间:2018-10-24 11:16:17

标签: java android android-intent whatsapp

导航栏中的共享都可以完美运行,但是在WhatsApp中,它仅显示链接而不是文本。

所有其他应用程序都可以完美地实现电报,邮件等...但是在WhatsApp中,它仅显示链接,而不显示大写文本。

try {
    Intent shareIntent = new Intent(android.content.Intent.ACTION_SEND);
    final String appPackageName = getApplicationContext().getPackageName();
    String strAppLink = "https://play.google.com/store/apps/details?id=" + appPackageName;
    shareIntent.setType("text/plain");
    String shareBody = strAppLink;
    String shareSub = "Hey Download this App Called\n Appname ........\nAt least One Time Try This\n";
    shareIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, shareSub);
    shareIntent.putExtra(android.content.Intent.EXTRA_TEXT, shareBody);
    startActivity(Intent.createChooser(shareIntent, "Share using"));
}
catch (ActivityNotFoundException e)
{

}

1 个答案:

答案 0 :(得分:1)

尝试

在Java中:

try {
        Intent shareIntent = new Intent(android.content.Intent.ACTION_SEND);
        final String appPackageName = getApplicationContext().getPackageName();
        String strAppLink = "https://play.google.com/store/apps/details?id=" + appPackageName;
        shareIntent.setType("text/plain");
        String shareBody = strAppLink;
        String shareSub = "Hey Download this App Called\n Appname ........\nAt least One Time Try This\n";
        String data = shareSub + shareBody
        // shareIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, shareSub);
        shareIntent.putExtra(android.content.Intent.EXTRA_TEXT, data);
        startActivity(Intent.createChooser(shareIntent, "Share using"));
    } catch (ActivityNotFoundException e) {

    }

在科特林:

 try {
        val shareIntent = Intent(android.content.Intent.ACTION_SEND)
        val appPackageName = applicationContext.packageName
        val strAppLink = "https://play.google.com/store/apps/details?id=$appPackageName"
        shareIntent.type = "text/plain"
        val shareSub = "Hey Download this App Called\n Appname ........\nAt least One Time Try This\n"
        val data = shareSub + strAppLink
        //shareIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, shareSub)
        shareIntent.putExtra(android.content.Intent.EXTRA_TEXT, data)
        startActivity(Intent.createChooser(shareIntent, "Share using"))
    } catch (e: ActivityNotFoundException) {

    }

只有一项更改是注释设置主题的行。将主题文本与文本合并,然后在 android.content.Intent.EXTRA_TEXT 中设置合并的文本。

有效。