首页 > 解决方案 > 分享图片缩略图和标题中的文字,如 Instagram 分享到 WhatsApp Android

问题描述

在此处输入图像描述

我需要将内容分享到 whatsapp,就像 Instagram 在附图中所做的那样。

标题部分有图像和标题文本和链接的缩略图然后消息部分有一个链接。

消息部分是直截了当的。任何有关实施标题部分的帮助都会有所帮助。

Intent sendIntent = new Intent();   
sendIntent.setAction(Intent.ACTION_SEND);   
sendIntent.putExtra(Intent.EXTRA_TITLE, "title text");   
sendIntent.putExtra(Intent.EXTRA_TEXT, "message section");   
sendIntent.setType("text/plain"); 
startActivity(sendIntent);

我已经浏览了 whatsapp 常见问题解答,但他们没有提到从意图处理的标签列表。

https://faq.whatsapp.com/en/android/28000012

标签: androidandroid-intentwhatsappandroid-sharing

解决方案


试试下面的代码

Uri imgUri = Uri.parse(pictureFile.getAbsolutePath());
    Intent intent = new Intent(Intent.ACTION_SEND);
    intent.setType("text/plain");
    intent.setPackage("com.whatsapp");
    intent.putExtra(Intent.EXTRA_TEXT, "The text you wanted to share");
    intent.putExtra(Intent.EXTRA_STREAM, imgUri);
    intent.setType("image/jpeg");
    intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);

    try {
        activity.startActivity(intent);
    } catch (android.content.ActivityNotFoundException ex) {
        Toast.MakeText(this,"Whatsapp not found",Toast.LENGTH_SHORT).show();
    }

推荐阅读