通过WhatsApp分享图像和文本

5
我使用以下代码通过 WhatsApp 分享图像和文本。然而,它只分享了图像,没有分享文本。我已经在互联网上搜索过,但没有找到解决方案。
 String message = Fname + Mobileno + Homeno + Workmail + Homemail
                + Gtalk + Skype + Address + Company + Title + Website;
      Intent shareIntent = new Intent(Intent.ACTION_SEND); 
      Uri uri = Uri.parse("file://"
                + Environment.getExternalStorageDirectory()
                + "/Talk&Share/Images/profpic.png");

      shareIntent.putExtra(Intent.EXTRA_TEXT, message); 
      shareIntent.putExtra(Intent.EXTRA_SUBJECT, "Contact"); 
      if(uri != null){
       shareIntent.putExtra(Intent.EXTRA_STREAM, uri);
       shareIntent.setType("image/plain");
      }else{
       shareIntent.setType("plain/text");
      }

         return shareIntent; 

https://dev59.com/4oPba4cB1Zd3GeqPz_ws#26772262 - Bhavin Chauhan
4个回答

10

Whatsapp支持文本与图片一起分享。

Intent shareIntent = new Intent();
shareIntent.setAction(Intent.ACTION_SEND);
shareIntent.putExtra(Intent.EXTRA_TEXT,title + "\n\nLink : " + link );
shareIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse(imageFilePath));
shareIntent.setType("image/*");
startActivity(Intent.createChooser(shareIntent, "Share image via:"));

这将分享图片,EXTRA_TEXT 将被视为图片标题。


8

使用:

Intent.ACTION_SEND_MULTIPLE

替代:

Intent.ACTION_SEND

3
这是不可能的,因为WhatsApp不支持同时包含图片和文本的信息。一条消息可以由单张图片、文本序列、音频文件、联系人或视频组成,但不能混合使用。

有没有办法在使用共享操作提供程序时检测分享者是哪个应用程序?这样我就可以使用不同的意图。 - Basim Sherif
@BasimSherif 我不知道有这样的事情。 - Raghav Sood
1
它以前不支持,但现在它可以工作了。https://dev59.com/4oPba4cB1Zd3GeqPz_ws#26772262 - Bhavin Chauhan

-1
Intent i = new Intent(android.content.Intent.ACTION_SEND);
 i.setType("text/plain");
 i.putExtra(Intent.EXTRA_SUBJECT, "Subject");
 i.putExtra(Intent.EXTRA_TEXT, "Message body");
startActivity(Intent.createChooser(i, "Share dialog title"));

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接